Cross-site scripting is gonna HTTP GET you

February 10th, 2010 | Posted by Quixey in Technology

While adding Markdown support for Quixey, we realized that Markdown’s support for raw HTML created an enormous cross-site scripting vulnerability.

We consulted the XSS Cheat Sheet and learned that there are hundreds of sinister tricks for hackers to inject malicious JS into any input field that offers a bare minimum of HTML support.

We decided to parse Markdown by disabling raw HTML input before invoking the Showdown converter, like this:

function markdownToSafeHtml(s) {

// Escape HTML characters while leaving ">" (Markdown
// quote syntax) intact, then parse with Markdown


var e = s.replace(/&/g, "&amp;").replace(/</g, "&lt;");
var converter = new Showdown.converter();
return converter.makeHtml(e);

}

Afterwards, we kept reading the XSS Cheat Sheet page just to make sure that Quixey wouldn’t be vulnerable to another hacker trick. Then we saw this XSS trick:

<img src="http://www.thesiteyouareon.com/somecommand.php?somevariables=maliciouscode">

Here’s how the attack works:

  1. Hacker uses Markdown to make an image whose source is an admin URL on your domain.
  2. One of your administors logs in and views the HTML-rendered version of the hacker-submitted markdown.
  3. Your administrator’s browser makes an HTTP GET request to some admin URL that is used to, say, reset someone’s password.
  4. The password reset operation is successful, because the administrator’s browser sent a cookie verifying that the administrator is logged in.

The root of the problem is that it’s extremely easy to use XSS to get authorized users to make HTTP GET requests — whereas POST requests are somewhat harder to XSS-hack.

The solution is to follow the HTTP protocol guidelines and require the user agent to make a POST for any operation that modifies server-side data.

So don’t think your data is safe just because you’re checking if your user is authenticated as an administrator. Make sure a hacker can’t use cross-site scripting to HTTP GET you.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

One Response



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>