Dev.Lib
arrow_backBack to Blogs
LEVEL_066.5June 27, 20261 min read

Same-origin policy nuances

Web Security

Origin = scheme + host + port.

Summary

Origin = scheme + host + port. Documents iframes cross-origin can't read DOM; postMessage with origin check for communication. CORS relaxes reading cross-origin responses, not sending. Cookies scoped by domain/path/SameSite — different from SOP. document.domain is legacy — don't use.

Code example

iframe.contentWindow.postMessage({ type: 'PING' }, 'https://trusted.example.com');

window.addEventListener('message', (event) => {
  if (event.origin !== 'https://trusted.example.com') return;
  handleMessage(event.data);
});

Key points

  • Origin = scheme + host + port.
  • Documents iframes cross-origin can't read DOM; postMessage with origin check for communication.
  • CORS relaxes reading cross-origin responses, not sending.
  • Cookies scoped by domain/path/SameSite — different from SOP.
  • document.domain is legacy — don't use.

Further reading

Related concepts