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.

64 Chapter 3 n Web Application Technologies<br />

Same-Origin Policy<br />

The same-origin policy is a key mechanism implemented within browsers that<br />

is designed to keep content that came from different origins from interfering<br />

with each o<strong>the</strong>r. Basically, content received from one <strong>web</strong>site is allowed to read<br />

and modify o<strong>the</strong>r content received from <strong>the</strong> same site but is not allowed to<br />

access content received from o<strong>the</strong>r sites.<br />

If <strong>the</strong> same-origin policy did not exist, and an unwitting user browsed to a<br />

malicious <strong>web</strong>site, script code running on that site could access <strong>the</strong> data and<br />

functionality of any o<strong>the</strong>r <strong>web</strong>site also visited by <strong>the</strong> user. This may enable <strong>the</strong><br />

malicious site to perform funds transfers from <strong>the</strong> user’s online bank, read his<br />

or her <strong>web</strong> mail, or capture credit card details when <strong>the</strong> user shops online. For<br />

this reason, browsers implement restrictions to allow this type of interaction<br />

only with content that has been received from <strong>the</strong> same origin.<br />

In practice, applying this concept to <strong>the</strong> details of different <strong>web</strong> features and<br />

technologies leads to various complications and compromises. Here are some<br />

key features of <strong>the</strong> same-origin policy that you need to be aware of:<br />

n A page residing on one domain can cause an arbitrary request to be made<br />

to ano<strong>the</strong>r domain (for example, by submitting a form or loading an<br />

image). But it cannot itself process <strong>the</strong> data returned from that request.<br />

n A page residing on one domain can load a script from ano<strong>the</strong>r domain and<br />

execute this within its own context. This is because scripts are assumed<br />

to contain code, ra<strong>the</strong>r than data, so cross-domain access should not lead<br />

to disclosure of any sensitive information.<br />

n A page residing on one domain cannot read or modify <strong>the</strong> cookies or<br />

o<strong>the</strong>r DOM data belonging to ano<strong>the</strong>r domain.<br />

These features can lead to various cross-domain attacks, such as inducing<br />

user actions and capturing data. Fur<strong>the</strong>r complications arise with browser<br />

extension technologies, which implement same-origin restrictions in different<br />

ways. These issues are discussed in detail in Chapter 13.<br />

HTML5<br />

HTML5 is a major update to <strong>the</strong> HTML standard. HTML5 currently is still under<br />

development and is only partially implemented within browsers.<br />

From a security perspective, HTML5 is primarily of interest for <strong>the</strong> following<br />

reasons:<br />

n It introduces various new tags, attributes, and APIs that can be leveraged<br />

to deliver cross-site scripting and o<strong>the</strong>r attacks, as described in<br />

Chapter 12.

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

Saved successfully!

Ooh no, something went wrong!