On this page
  1. Same-Origin Policy & CORS
  2. Contents
  3. What Defines an Origin
  4. Simple vs. Preflighted (OPTIONS) Requests
  5. Key CORS Response Headers

Same-Origin Policy & CORS

Prev: security | Up: security | Next: CSP, Cookies & XSS/CSRF Mitigations
Rel: Fetch & Networking, Python Web Development & APIs
Ref: MDN Web Docs — Cross-Origin Resource Sharing (CORS)
Tags: #public #web #platform #security #http #cors


Contents


What Defines an Origin

Two URLs share the same origin only when scheme, host, and port all match exactly. The browser's Same-Origin Policy (SOP) blocks JavaScript from reading responses across origins unless the server explicitly opts in via CORS headers.


Simple vs. Preflighted (OPTIONS) Requests


Key CORS Response Headers

Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 600

Note: Access-Control-Allow-Origin: * cannot be combined with Access-Control-Allow-Credentials: true (or fetch(url, { credentials: "include" })); the server must echo an explicit trusted origin and include Vary: Origin.

Linked from

Related notes