Fortify’s Announcement About Jeremiah’s Attack, Decoded
Thomas Ptacek | April 2nd, 2007 | Filed Under: New Findings, Uncategorized
Thing 1.
Javascript is a dynamic language. You can redefine or override core features of the language or the API. When your browser evaluates a Javascript program, that program can set up functions to get called when all sorts of things happen, such as when object attributes are changed or accessed or arrays are modified.
Thing 2.
Many (perhaps most) modern web apps are vulnerable to XSRF: they have HTTP GET or POST URLs which, if you can trick a victim into following a link (or loading an image, or following a SCRIPT tag), will “do things” inside of the application: delete your mail, change your Google language, Digg a story, etc.
We’re all working on smoking these URLs out because it is very easy to trick browsers into hitting them, even if they’re POST-only. We’re nowhere close to done.
Thing 3.
AJAX applications often hook your browser and the application server up using JSON, which is simply Javascript describing arrays and tables. The important detail here: the data itself is described directly in Javascript, not as a data format that the AJAX code in the browser parses.
Thing 1 and Thing 2 and Thing 3.
You get a victim to visit a web page you control. It contains Javascript code that redefines methods on Object, or arrays, or callback functions, or whatever.
It also contains, say, a SCRIPT tag aimed at an XSRF-able URL in your target application (say, your banking site).
The result of the XSRF-able URL is a JSON “document” (really, “script”). It’s got sensitive stuff in it (say, your account numbers or balances or whatever).
You can’t directly read this document. But the browser executes it, because that’s how you “parse” JSON documents: you eval them as a script and take the results, neatly packaged as Javascript objects.
But you don’t have to read the document directly. You redefined key Javascript functions before loading the script, setting up code that gets called as the JSON script is evaluated. The Javascript engine feeds you the data from the document as it’s loaded.
You win.
The Moral Of This Story
Cross-Site Request Forgery (XSRF) is bad.
You can monkeywrench this particular instance of XSRF by booby-trapping your JSON documents. Just make sure they won’t evaluate properly without some pre-processing step. For instance, your bank can stick an infinite loop at the top of the JSON doc. Your bank’s own legitimate AJAX Javascript code can strip it out. Your oblivious attacker’s Javascript can’t.
You can make sure sensitive JSON data only goes out via POST. The SCRIPT tag uses GET.
You can fix XSRF vulnerabilities: validate incoming requests with a nonce value, which ensures that requests for data are tied to actual legitimate application code.
You can stop using JSON. You’re unlikely to do so; JSON is extremely convenient (rich data types, no parsing). But if you had used XML, there might not have been a trivial way to snoop the documents.


Add New Comment
Viewing 5 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks