CORS (Cross-Origin Resource Sharing) is a browser-enforced mechanism that governs when JavaScript running on one origin (scheme + host + port) is allowed to read the response of an HTTP request made to a different origin. It's a controlled relaxation of the browser's default same-origin policy, defined as part of the WHATWG Fetch Standard (originally a W3C Recommendation).
By default, a browser lets a page send a cross-origin request but blocks JavaScript from reading the response unless the server opts in with CORS response headers — most importantly Access-Control-Allow-Origin, naming which origin(s) may read the response. For a "simple" request (GET/HEAD/POST with only a few allowed headers and content types), the browser sends the real request directly and just checks the response header. For anything more (custom headers, PUT/DELETE, non-form content types like application/json), the browser first sends an automatic preflight OPTIONS request asking the server what's allowed, and only proceeds with the real request if the server's answer permits it.
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: true
CORS is entirely a browser-side protection — it does nothing to stop a server-to-server request or a tool like curl from reading a cross-origin response, since neither enforces the same-origin policy in the first place.
Access-Control-Allow-Origin: * (allow any origin) can't be combined with Access-Control-Allow-Credentials: true — browsers reject that combination, since it would let any site read credentialed responses.Origin header back verbatim as Access-Control-Allow-Origin (to "support" every origin) defeats the purpose of CORS as an access control and should be paired with an actual allowlist check.