Questions tagged [same-origin-policy]

The same origin policy, which is enforced by Web browsers, limits JavaScript in a document loaded from one origin from accessing data from another origin. The limitation can be relaxed using the CORS protocol.

The same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. The policy prevents (by default) pages interacting with resources from a different origin. They are means to work around this such as using mechanisms that grant permission, data formats that aren't subject to the policy and intermediary servers, and — most significantly, the CORS protocol.

This mechanism bears a particular significance for modern web applications that extensively depend on HTTP cookies to maintain authenticated user sessions, as servers act based on the HTTP cookie information to reveal sensitive information or take state-changing actions. A strict separation between content provided by unrelated sites must be maintained on client side to prevent the loss of data confidentiality or integrity.

See also:

1134 questions
3256
votes
15 answers

Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?

Mod note: This question is about why XMLHttpRequest/fetch/etc. on the browser are subject to the Same Access Policy restrictions (you get errors mentioning CORB or CORS) while Postman is not. This question is not about how to fix a "No…
Mr Jedi
  • 33,658
  • 8
  • 30
  • 40
854
votes
15 answers

How can I access the contents of an iframe with JavaScript/jQuery?

I would like to manipulate the HTML inside an iframe using jQuery. I thought I'd be able to do this by setting the context of the jQuery function to be the document of the iframe, something like: $(function(){ //document ready $('some selector',…
rz.
  • 19,861
  • 10
  • 54
  • 47
819
votes
9 answers

SecurityError: Blocked a frame with origin from accessing a cross-origin frame

I am loading an