Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add json prefix to prevent script tag csrf attack #76

Closed
FranzPoize opened this issue Apr 5, 2013 · 4 comments
Closed

Add json prefix to prevent script tag csrf attack #76

FranzPoize opened this issue Apr 5, 2013 · 4 comments

Comments

@FranzPoize
Copy link

According to http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx it is possible to attack a json response by transforming it into jsonp.

Adding a prefix like suggested in http://docs.angularjs.org/api/ng.$http (JSON Vulnerability Protection).

I did it in my fork 3d73cf6 in the class serializer, but maybe it would be good to do it in the JsonSerializationVisitor.

@marcospassos
Copy link
Contributor

Seems a good addition.

@stof
Copy link
Contributor

stof commented Apr 5, 2013

The issue is that your return value is not JSON anymore. So if you put the prefix, you have to change the content-type of your response to avoid lying, and client code must be aware that the prefix needs to be stripped to retrieve the JSON. So a JSON visitor should not do it by default.

FYI, the PR implementing it for Symfony uses text/javascript) for prefixed responses (which is also what Google uses)

@stof
Copy link
Contributor

stof commented Apr 5, 2013

Thus, if you always return an object in your response rather than an array, you are not affected by the vulnerability, as mentionned in the blog post.

@schmittjoh
Copy link
Owner

I think this is outside the scope of the serializer.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants