Glossary termWeb security mechanism

Cross-Origin Resource Sharing

Also known as: CORS

Browser security mechanism that uses HTTP headers to let a server state which other websites may read its responses through scripts.

Cross-Origin Resource Sharing (CORS) is a standard that controls when a script running on one website may read data from another. Browsers enforce the same-origin policy, which by default prevents a page's JavaScript from reading responses from a different origin, meaning a different combination of scheme, domain and port. CORS provides a controlled exception. A server that wants to share its data includes HTTP response headers, such as Access-Control-Allow-Origin, naming the origins allowed to read it, and the browser checks those headers before handing the response to the script.

For requests that could change data or that use custom headers, the browser first sends a preflight request using the OPTIONS method, asking the server whether the real request is permitted, and proceeds only if the answer allows it. Requests carrying cookies or other credentials face stricter rules: the server must explicitly allow credentials and cannot use a wildcard for the allowed origin. Netscape introduced the same-origin policy in the mid-1990s alongside JavaScript. CORS was developed at the W3C to give web applications a safe way to call APIs on other domains, and its definition was later folded into the WHATWG Fetch standard.

CORS is a frequent source of confusion for developers, who meet it as an error blocking a request that works from other tools. The key point is that CORS protects users rather than servers: it stops a malicious site from using a visitor's browser, and that visitor's logged-in cookies, to read private data from another site. It does not stop non-browser clients, so servers still need proper authentication. Misconfigurations, such as reflecting any requesting origin while allowing credentials, can expose sensitive data and are a recognized class of web vulnerability.

Key points

  • The same-origin policy blocks scripts from reading other sites' responses unless CORS headers permit it.
  • Servers opt in with headers such as Access-Control-Allow-Origin, naming the origins allowed to read responses.
  • Preflight OPTIONS requests check permission before requests that could change data or use custom headers.
  • Overly permissive CORS settings, especially combined with credentials, can expose private user data.

Related entries

Glossary term

HTTP

ProgrammingCybersecurity

Stateless request-response protocol that web browsers, servers and other clients use to request and transfer resources such as web pages and data.

Technology

JavaScript

Programming

High-level programming language of the web, created at Netscape in 1995, that runs in every major browser and on servers through runtimes like Node.js.

Glossary term

API

Programming

Defined set of rules and interfaces through which one piece of software can request services or data from another without knowing its internals.

Glossary term

Cross-Site Scripting

CybersecurityProgramming

Web vulnerability that lets attackers inject malicious scripts into pages viewed by other users, which then run with the trust of the affected site.

Glossary term

Authentication

Cybersecurity

The process of verifying that a person, device or system is who or what it claims to be before granting access to resources.

Organization

World Wide Web Consortium

ProgrammingIdeas and Culture

International standards organization that develops open technical standards and guidelines for the World Wide Web, including CSS and accessibility guidelines.

Glossary term

Vulnerability

Cybersecurity

A weakness in software, hardware, configuration or process that an attacker could exploit to compromise confidentiality, integrity or availability.

Glossary term

REST API

ProgrammingAI

Web interface that follows the REST architectural style, exposing resources at URLs that clients manipulate with stateless HTTP requests.

Referenced by

Other entries that discuss or point to Cross-Origin Resource Sharing.