19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13 n Attacking Users: O<strong>the</strong>r Techniques 523<br />

E4X<br />

In <strong>the</strong> recent past, E4X has been a fast-evolving area, with browser behavior<br />

being frequently updated in response to exploitable conditions that have been<br />

identified in numerous real-world <strong>application</strong>s.<br />

E4X is an extension to ECMAScript languages (including JavaScript) that adds<br />

native support for <strong>the</strong> XML language. At <strong>the</strong> present time, it is implemented in<br />

current versions of <strong>the</strong> Firefox browser. Although it has since been fixed, a classic<br />

example of cross-domain data capture can be found in Firefox’s handling of E4X.<br />

As well as allowing direct usage of XML syntax within JavaScript, E4X allows<br />

nested calls to JavaScript from within XML:<br />

var foo={prompt(‘Please enter <strong>the</strong> value of bar.’)};<br />

These features of E4X have two significant consequences for cross-domain<br />

data-capture attacks:<br />

n A piece of well-formed XML markup is treated as a value that is not<br />

assigned to any variable.<br />

n Text nested in a {...} block is executed as JavaScript to initialize <strong>the</strong><br />

relevant part of <strong>the</strong> XML data.<br />

Much well-formed HTML is also well-formed XML, meaning that it can be<br />

consumed as E4X. Fur<strong>the</strong>rmore, much HTML includes script code in a {...}<br />

block that contains sensitive data. For example:<br />

<br />

<br />

<br />

...<br />

function setNonce()<br />

{<br />

nonce = ‘222230313740821’;<br />

}<br />

...<br />

<br />

<br />

<br />

...<br />

<br />

<br />

In earlier versions of Firefox, it was possible to perform a cross-domain script<br />

include of a full HTML response like this and have some of <strong>the</strong> embedded<br />

JavaScript execute within <strong>the</strong> attacker’s domain.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!