-
Notifications
You must be signed in to change notification settings - Fork 264
Docs for getJSON() should specify under what conditions it is secure #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this, @davidwagner. Let's close #755 in favor of this one and just add a note to all Ajax methods. |
This seems out of the scope of the API docs. The docs already specify that That said, if anyone has a short message we can add we could consider it. The $.ajax docs are already long and tedious to read though, so any addition may just get lost in the existing text. Lacking more specifics I'll close this. |
What about adding "If you don't trust the target of your Ajax requests, consider setting the |
That's nice and short, if you can find a place to put it. |
Perhaps close to the |
Sure, works for me. |
Closed via e98feb7. |
The documentation for getJSON() should mention the conditions under which it causes a XSS vulnerability, and describe what developers need to do to avoid introducing XSS when using getJSON().
In particular,
$.getJSON(untrusted_url, function(...) {...})
is unsafe, ifuntrusted_url
comes from an untrusted source (e.g., from the attacker, from another user). If the attacker controlsevil.com
, the attacker can arrange foruntrusted_url
to hold something likehttp://evil.com/callback=?
and then arrange forevil.com
to respond to that request with malicious Javascript. JQuery's JSONP auto-detection will then eval the Javascript found in the response to that request, making the$.getJSON()
call a XSS vulnerability.This is a foot-gun. It's not clear from the documentation for
getJSON()
that it can introduce this kind of vulnerability when part or all of the URL can be controlled by the attacker. Documenting this more clearly would help developers avoid inadvertent XSS vulnerabilities in their code.[Is the following still true? I have not verified it, and it might no longer be the only safe way.] Apparently if the URL might be partially or completely under attacker control, the only safe way to fetch JSON from that URL is to use
$.ajax(url, {dataType: 'json', jsonp: false});
. This fact is not apparent from the documentation -- it should be described in the documentation more clearly.See http://stackoverflow.com/q/29022794/ for details.
Re-filed from jquery/jquery#2173, as that was the wrong place to file it. See also #755 and #732; this could be combined with those two. Probably it suffices to have one issue to cover these, but I thought I'd record the full details and justification so there's a description of them.
The text was updated successfully, but these errors were encountered: