Generated by GPT-5-mini| CORS | |
|---|---|
| Name | CORS |
| Focus | Web security, HTTP |
| Introduced | 2004 |
| Standards | W3C, IETF |
| Related | HTTP, Same-Origin Policy, XMLHttpRequest |
CORS
Cross-origin resource sharing (CORS) is a web security mechanism that enables controlled access to resources located outside a given origin. It augments the Same-Origin Policy model used by browsers such as Google Chrome, Mozilla Firefox, Safari, and Microsoft Edge by allowing servers to indicate permitted cross-origin requests. CORS interactions typically involve web applications hosted on domains associated with services like Amazon Web Services, Google Cloud Platform, Microsoft Azure, and content delivery systems such as Akamai Technologies.
CORS emerged in response to limitations of the Same-Origin Policy as web applications grew more distributed across domains like example.com and services including Facebook Platform, Twitter API, and GitHub Pages. Early proposals and discussions involved participants from World Wide Web Consortium working groups and engineers at Mozilla Foundation, Opera Software, and Microsoft Corporation. The specification evolved through drafts and alignments with protocols such as HTTP/1.1 and later interactions with Fetch Standard work by contributors from WHATWG and W3C. Real-world pressure from platforms like Google Maps, YouTube, and Stripe (company) motivated standardization to enable safe cross-origin XMLHttpRequest and Fetch API usage.
CORS operates via HTTP headers exchanged between clients and servers. A typical flow uses request headers such as Origin sent by clients like Axios (software), jQuery, or native browser fetch implementations from Apple Inc. and Samsung Electronics. Servers respond with headers like Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers, which are honored by browsers developed by teams at Google, Mozilla, Apple, and Microsoft. For non-simple requests, the mechanism uses preflight OPTIONS requests where user agents check allowed methods and headers before issuing requests that involve credentials or custom headers, a behavior implemented in engines such as Blink, Gecko, and WebKit. The interaction ties into authentication patterns used by OAuth 2.0, JSON Web Token, and cookies managed across domains registered through registrars like ICANN-accredited providers.
CORS is designed to mitigate cross-origin attacks while permitting legitimate cross-site interactions. Misconfiguration can create vulnerabilities exploited in incidents involving platforms like PayPal, Stripe (company), or social networks such as Facebook and Twitter. Attack vectors include overly permissive wildcard responses, incorrect handling of credentials, and echoing of unvalidated Origin headers—issues discussed in advisories from vendors like Mozilla Foundation and Google Security Team. Security frameworks and audits by organizations such as OWASP and standards work at IETF emphasize strict validation, use of Access-Control-Allow-Credentials only when necessary, and combining CORS with measures like Content Security Policy from W3C and secure cookie attributes promoted by IETF.
Servers implement CORS in web servers and frameworks like Apache HTTP Server, Nginx, Microsoft IIS, Node.js, Express (web framework), Django, Ruby on Rails, and Spring Framework. Cloud gateways and proxies from Cloudflare, Amazon CloudFront, Google Cloud Load Balancing, and Fastly often provide configuration panels or edge rules to set Access-Control headers. Many platforms expose middleware packages—examples include middleware for ASP.NET Core, packages published to npm, plugins for WordPress, and modules for NGINX maintained by community contributors. Administrators typically specify allowed origins, methods, headers, credential policies, and caching of preflight responses following guidance from standards bodies like W3C and browser vendors including Google and Mozilla.
User agents implement CORS policies across engines developed by organizations such as Google, Mozilla, Apple, and Microsoft. Browsers enforce header checks and may block access to responses that do not include appropriate Access-Control-Allow-* headers; they surface errors in developer tools used by engineers at firms like GitHub, Atlassian, and Stack Overflow. Servers must decide whether to reflect the Origin header, use static allowlists, or implement dynamic policies tied to back-end identity systems like OAuth 2.0 providers (for example, Auth0, Okta). Intermediaries such as reverse proxies from NGINX, Inc. or API gateways from Kong (company) and Tyk (software) can modify or enforce headers, which affects how browsers from Samsung and Mozilla interpret responses.
CORS is applied in single-page applications hosted on platforms like Netlify and Vercel that call APIs on AWS API Gateway or Google Cloud Functions, in mashups combining services such as YouTube embeds with analytics from Google Analytics, and in integrations between SaaS offerings like Salesforce and Zendesk. Examples include allowing AJAX requests from a frontend on GitHub Pages to an API on Heroku, configuring Access-Control-Allow-Origin for a microservice cluster running on Kubernetes, and enabling third-party widgets served by networks like Akamai Technologies. Developers consult documentation from browser vendors like Mozilla Developer Network and platform providers such as Amazon Web Services, Google Cloud Platform, and Microsoft Azure when implementing and debugging policies.
Category:Web security