Saturday, January 12, 2013

Abusing Open Redirects To Bypass XSS Filters

Open redirects can very often be escalated to reflected cross site scripting, in fact they can even be abused to bypass strict XSS filters depending on the way the redirect is performed. During a recent penetration test I encountered an example very similar to the following:


Response Body:


The target application had very strict XSS filters in place, any request with parameters containing quotes, brackets, angle brackets, etc... were immediately rejected and displayed a generic error page.

Consider what happens if we pass the following parameter to the function:

Base64 decoded, the above reads:
<script>alert("cookie: "+document.cookie)</script>

It would look like this, note the URL encoded part is just the payload above, and does not contain any characters that would set off an XSS filter. Also the hashtag on the end is to truncate the payload so that any extraneous parameters that the webserver adds in the response (in this case someRandomParam1 and someRandomPara2) are not interpreted as part of the javascript payload:


Response Body:


The following is a screenshot showing the result in the latest version of FireFox:

It's somewhat surprising that this does in fact work since redirects via the "Location:" header are not susceptible to this type of attack. A redirect to a "data:" or "javascript:" URL via the location header will have the script run in it's own context.

Possibly an oversight on the side of the browser vendors JS parser?


  1. Wow. This is incredible. It doesn't seem to work in Chrome (Chromium at least) any more.

    1. I'm not sure what the current state of this one would be. I think a lot of newer browsers might be mitigating this sort of thing now-a-days.