19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

To understand more fully <strong>the</strong> consequences of <strong>the</strong> same-origin policy for<br />

<strong>web</strong> <strong>application</strong> security, this section examines some fur<strong>the</strong>r contexts in<br />

which <strong>the</strong> policy applies and how certain cross-domain attacks can arise in<br />

those contexts.<br />

The Same-Origin Policy and Browser Extensions<br />

The browser extension technologies that are widely deployed all implement<br />

segregation between domains in a way that is derived from <strong>the</strong> same basic<br />

principles as <strong>the</strong> main browser same-origin policy. However, some unique<br />

features exist in each case that can enable cross-domain attacks in some<br />

situations.<br />

The Same-Origin Policy and Flash<br />

Flash objects have <strong>the</strong>ir origin determined by <strong>the</strong> domain of <strong>the</strong> URL from which<br />

<strong>the</strong> object is loaded, not <strong>the</strong> URL of <strong>the</strong> HTML page that loads <strong>the</strong> object. As<br />

with <strong>the</strong> same-origin policy in <strong>the</strong> browser, segregation is based on protocol,<br />

hostname, and port number by default.<br />

In addition to full two-way interaction with <strong>the</strong> same origin, Flash objects<br />

can initiate cross-domain requests via <strong>the</strong> browser, using <strong>the</strong> URLRequest<br />

API. This gives more control over requests than is possible with pure browser<br />

techniques, including <strong>the</strong> ability to specify an arbitrary Content-Type header<br />

and to send arbitrary content in <strong>the</strong> body of POST requests. Cookies from <strong>the</strong><br />

browser’s cookie jar are applied to <strong>the</strong>se requests, but <strong>the</strong> responses from<br />

cross-origin requests cannot by default be read by <strong>the</strong> Flash object that initiated<br />

<strong>the</strong>m.<br />

Flash includes a facility for domains to grant permission for Flash objects from<br />

o<strong>the</strong>r domains to perform full two-way interaction with <strong>the</strong>m. This is usually<br />

done by publishing a policy file at <strong>the</strong> URL /crossdomain.xml on <strong>the</strong> domain<br />

that is granting permission. When a Flash object attempts to make a two-way<br />

cross-domain request, <strong>the</strong> Flash browser extension retrieves <strong>the</strong> policy file<br />

from <strong>the</strong> domain being requested and permits <strong>the</strong> request only if <strong>the</strong> requested<br />

domain grants access to <strong>the</strong> requesting domain.<br />

Here’s an example of <strong>the</strong> Flash policy file published by www.adobe.com:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!