Cross-Origin Resource Sharing
Cross-Origin Resource Sharing is a browser-enforced mechanism that controls whether scripts running on one web origin are permitted to read responses from a different origin. Browsers apply the same-origin policy by default, which restricts script access to cross-origin responses, and CORS provides a way for servers to explicitly grant or restrict that access using HTTP headers. It does not block all cross-origin requests outright, but it does govern whether the browser will expose response content to the requesting script.
CORS is an HTTP-header-based mechanism through which a server communicates to a browser which origins, outside the server's own origin (defined by scheme, host, and port), are permitted to have script-level access to its responses. When a browser-based script initiates a cross-origin request, the browser enforces the same-origin policy by default, restricting script access to the response unless the server includes permissive Access-Control-Allow-Origin and related headers. For requests that may have side effects (typically non-simple requests), the browser first issues a preflight OPTIONS request to determine server permissions before sending the actual request. Credential-bearing cross-origin requests require the server to respond with a specific origin value in Access-Control-Allow-Origin (wildcards are not accepted for credentialed requests) and to include Access-Control-Allow-Credentials: true; without both, the browser withholds the response from the script. CORS operates at the browser level and does not restrict server-side receipt of requests, meaning non-browser clients are unaffected by CORS headers.
Why it matters
Web applications routinely need to load resources from multiple origins, whether calling a third-party API, fetching assets from a CDN, or communicating with a separate backend service. Without a controlled mechanism for cross-origin access, browsers would leave users exposed to scripts silently reading sensitive responses from other sites using the user's credentials. CORS is the standardized mechanism that allows servers to declare which external origins may have script-level access to their responses, making legitimate cross-origin integration possible while preserving meaningful user protection.
Who it's relevant to
Inside CORS
Common questions
Answers to the questions practitioners most commonly ask about CORS.