Skip to main content
Definition Website Computer and Technology

Cross-Origin Resource Sharing

Subject: Computer and Technology noun /ˈkrɔːsˌɔːr.ɪ.dʒɪn ˈriː.sɔːrs ˈʃɛr.ɪŋ/ 1 definition

  1. Definition (noun)

    Entry #94 · Updated

    Cross-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 Origin header to cross-origin requests and validates server response headers such as Access-Control-Allow-Origin before 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, or POST with safelisted headers and content types (application/x-www-form-urlencoded, multipart/form-data, or text/plain), which the browser dispatches immediately with an Origin header and gates at read time using Access-Control-Allow-Origin.

    • Preflighted Requests: Cross-origin calls using non-safelisted methods (such as PUT, DELETE, or PATCH), custom headers (such as Authorization), or application/json payloads, prompting the browser to send a preliminary HTTP OPTIONS request to verify Access-Control-Allow-Methods and Access-Control-Allow-Headers before issuing the actual request.

    • Credentialed Requests: Cross-origin calls configured to send cookies, TLS client certificates, or HTTP authentication credentials (such as credentials: "include" in fetch), which browsers block unless the server returns Access-Control-Allow-Credentials: true paired with an explicit origin rather than the wildcard *.

    Example

    When a single-page web application at https://app.example.com sends a POST request with a JSON body and an Authorization bearer token to https://api.example.com/v1/orders, the browser first issues an HTTP OPTIONS preflight request carrying Origin: https://app.example.com. After api.example.com approves the preflight with Access-Control-Allow-Origin: https://app.example.com, Access-Control-Allow-Methods: POST, and Access-Control-Allow-Headers: Authorization, Content-Type, the browser dispatches the POST request and exposes its response once the server includes the matching Access-Control-Allow-Origin header.