Some of our clients have encountered an XSS vulnerability in all of our JSONP endpoints, but I do not agree if this is really a vulnerability. I wanted to know the opinion of the community to make sure that I did not miss something.
So, as with any jsonp system, we have an endpoint, for example:
http:
where the value of the cb parameter is reproduced back in the answer:
callback123({"foo":"bar"});
Clients complained that we were not filtering HTML in the CB parameter, so they would come up with an example like this:
http://foo.com/jsonp?cb=<body onload="alert('h4x0rd');"/>
Obviously, for a URL that returns a text/html content type, this creates a problem where the browser renders this HTML and then executes a potentially malicious javascript in the onload handler. It can be used to steal cookies and send them to an attacker’s site, or even to create a fake phishing login screen. The user checks the domain and sees that he trusts him, so he goes into age and enters the system.
But in our case, we set the header to the content type application/javascript , which causes various different behaviors in different browsers. that is, Firefox simply displays the raw text, whereas IE opens the "save as ..." dialog. I do not think this can be particularly useful. A Firefox user is not going to read malicious text telling him to jump off the bridge and think a lot. And the IE user will probably be confused with the Save As dialog and click Cancel.
I think I could see a case where an IE user is tricked into saving and opening a .js file, which then goes through the JScript engine for Microsoft and gets all kinds of access to the user machine; but that seems unlikely. Is this the biggest threat here, or is there some other vulnerability that I missed?
(Obviously, I'm going to “fix” by inserting filtering to only accept a valid javascript identifier, with some length restriction anyway, but I just need a dialog about what other threats I could skip.)