Origins and CORS
What an origin means
An origin identifies a web security boundary using scheme, host and effective port. A page at https://shop.example.com and another at https://shop.example.com/catalog share an origin; https://api.example.com has a different host and therefore a different origin. Paths do not define origins. The same-origin policy limits how scripts can access data from other origins, rather than blocking every cross-origin interaction.
What CORS permits
Cross-Origin Resource Sharing (CORS) uses HTTP response headers to let a browser expose certain cross-origin responses to scripts. For example, the bookstore API can allow its own shop origin by returning the following illustrative headers for a permitted credentialed request. The client must also request credentials and cookie policy must permit them.
Access-Control-Allow-Origin: https://shop.example.comAccess-Control-Allow-Credentials: trueVary: OriginPreflight and explicit allowlists
For some cross-origin requests, the browser sends a preliminary OPTIONS request to ask which methods and headers are allowed. A failed preflight prevents the corresponding actual request. Other requests can reach a server without a preflight. Compare origins exactly against a configured allowlist; never automatically reflect arbitrary origins. When the response varies by request origin, Vary: Origin helps caches keep the variants separate.
Common mistakes
A blocked CORS response does not imply the server did not receive or process the request. CORS is not server-side authorization; non-browser clients are not constrained by browser CORS enforcement. A wildcard allow-origin cannot authorize credentialed response sharing. Public, noncredentialed resources may intentionally allow any origin, but private records still need authentication and authorization.
Practice: classify browser decisions
Classify shop-to-API access, a change from HTTPS to HTTP, and a path-only change. Then review a credentialed response from the API with an exact allowed origin versus a wildcard. Explain separately whether the browser may expose the response and whether the server should authorize a private record. Use only these fictional addresses; no network calls.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Origins and CORS — knowledge check
Reason about browser and server controls using fictional cases.
Which change alone preserves origin?
What does a successful CORS check establish?
What happens after a failed required preflight?
Which allow-origin value fits a credentialed shop response?
Why use Vary: Origin on a response whose CORS policy depends on origin?