Search code examples
javascripthtmlsecuritysame-origin-policy

Same-Origin Policy: Understanding Deny Read


This MSDN article explains that READS are not permitted by the same-origin policy.

Specifically, it says:

Webpage from Origin A:

  • May include (execute) a frame pointed at a HTML page from “B”

  • Must not be permitted to get the inner HTML of that frame

How can another html file be "included (executed)", without the content of it being accessed?

What does "included (executed)" even mean in this context?


Solution

  • This is referring to the fact that the user viewing the page can see the content of the iframe, but scripts running on the framing page cannot access the content of the framed page. Consider analogously that an <img> tag will show an image from any origin to a user, but scripts within the page that contains the <img> tag might not be able to read the contents of the loaded image.

    This is important because the framed page is from a different origin and was fetched using the user's cookies from that origin. Suppose the framed page was mail.google.com: certainly I don't want any random webpage to read the contents of my inbox simply by loading it in an iframe. However, merely showing the page to me, the user who happens to be logged in to my mail service, is harmless.