Cross-Origin Resource Sharing
Subject: Computer and Technology noun /ˈkrɔːsˌɔːr.ɪ.dʒɪn ˈriː.sɔːrs ˈʃɛr.ɪŋ/ 1 definition
- web-security
- browser-security
- web-development
- http-headers
-
Definition (noun)
Entry #94 · UpdatedCross-Origin Resource Sharing (CORS) is a standardized HTTP-header-based mechanism that allows a server to declare which external origins—defined by the combination of scheme, hostname, and port—are permitted to access its resources from a web browser. By default, browsers enforce the Same-Origin Policy (SOP) to prevent scripts on one site from reading sensitive responses returned by another origin. CORS provides an opt-in, policy-controlled relaxation of that isolation: the browser attaches an
Originheader to cross-origin requests and validates server response headers such asAccess-Control-Allow-Originbefore dispatching non-simple requests or exposing responses to client-side code, while remaining a user-agent enforcement mechanism rather than a substitute for server-side authentication and authorization.Common Forms
Simple Requests: Cross-origin calls restricted to
GET,HEAD, orPOSTwith safelisted headers and content types (application/x-www-form-urlencoded,multipart/form-data, ortext/plain), which the browser dispatches immediately with anOriginheader and gates at read time usingAccess-Control-Allow-Origin.Preflighted Requests: Cross-origin calls using non-safelisted methods (such as
PUT,DELETE, orPATCH), custom headers (such asAuthorization), orapplication/jsonpayloads, prompting the browser to send a preliminary HTTPOPTIONSrequest to verifyAccess-Control-Allow-MethodsandAccess-Control-Allow-Headersbefore issuing the actual request.Credentialed Requests: Cross-origin calls configured to send cookies, TLS client certificates, or HTTP authentication credentials (such as
credentials: "include"infetch), which browsers block unless the server returnsAccess-Control-Allow-Credentials: truepaired with an explicit origin rather than the wildcard*.
Example
When a single-page web application at
https://app.example.comsends aPOSTrequest with a JSON body and anAuthorizationbearer token tohttps://api.example.com/v1/orders, the browser first issues an HTTPOPTIONSpreflight request carryingOrigin: https://app.example.com. Afterapi.example.comapproves the preflight withAccess-Control-Allow-Origin: https://app.example.com,Access-Control-Allow-Methods: POST, andAccess-Control-Allow-Headers: Authorization, Content-Type, the browser dispatches thePOSTrequest and exposes its response once the server includes the matchingAccess-Control-Allow-Originheader.