Cross-Site Request Forgery For POST Requests With An XML Body

I recently had cause to create a proof-of-concept for a site that seemed to be vulnerable to Cross-Site Request Forgery (CSRF).  I say “seemed” because there was no CSRF protection, but I was finding the XML POST body really hard to forge (It was a SOAP / XMLRPC type request).

Eventually Sid from pointed me in the right direction.  The solution is not new, but it’s interesting if you’ve never come across this problem before.

What I Was Trying To Achieve

I wanted to write a malicious web page, which would automatically send a request like the one below when a victim viewed it:

POST /createnewuser HTTP/1.1
Cookie: mysessionid=90450874698749829

<?xml version value='"1.0"?><methodCall>... new creds go here...</methodCall>

The Stuff That Didn’t Work

The most obvious approach is probably to have JavaScript automatically sumbit a form containing a hidden form field.  Below is my initial attempt.  Note that I stuff the XML into the “name” of a POST parameter.

 <FORM action="" METHOD="POST">
 <input type="hidden" name="<?xml version...">

This fails for 2 important reasons:

  1. The “name” containing my XML gets URL encoded thereby corrupting the body of the POST request
  2. There’s a stray “=” at the end of the request.  POST requests bodies are of the form “name=value&name2=value2”.  Since I specified only a single name with no value, the browser quite rightly appended an “=” after the name.

So my forged POST request looked something like this:

POST /createnewuser HTTP/1.1
Cookie: mysessionid=90450874698749829


No where close!

I also considered JavaScript’s XMLHttpRequest and Flash’s XML.Send, but these obviously won’t work because the request is cross-domain.

The Solution

Sid pointed out that  Shreeraj Shah presented an elegant solution to this problem in slide 34 of his HITB presentation in 2008.

To quote from his presentation, the poc should specify an ENCTYPE of  “text/plain”:

<FORM NAME="buy" ENCTYPE="text/plain"
action="" METHOD="POST">
<input type="hidden" name='<?xml version'

This results in a perfectly formatted Cross-Domain XML POST request.  The ENCTYPE avoids the body being encoded and he cleverly absorbs the unwanted “=” into the XML at a point where we need an “=” anyway.



Leave a Reply