Cross-origin resource sharing
With cross-origin resource sharing (CORS), a server names in its HTTP response headers the origins other than its own whose scripts may read its responses.1 The browser reads those headers and makes an exception to the same-origin policy, its default rule that keeps a script on one site from reading data from another.2 A server that names too many origins lets other websites read what its signed-in visitors can see.2
Same-origin policy
Two addresses have the same origin when their protocol, host and port match; a different path does not matter.3 https://app.example.com and https://api.example.com are different origins, as are http:// and https:// on the same host.
A page may send data to another origin through links, redirects and form submissions, and may embed images and scripts from it, but in general it may not read what the other origin returns.3 Because of that rule, a hostile page open in one tab cannot read a webmail inbox or an intranet page the same browser can reach.3 The fetch() and XMLHttpRequest interfaces follow it, so a front end on one origin that calls an API on another needs the API to answer with CORS headers.1
Mechanism
The browser adds an Origin header naming the page's origin to every cross-origin request. The server answers with Access-Control-Allow-Origin, which holds * (any origin), exactly one origin, or null. A server that accepts several origins checks the incoming Origin against its own list and repeats it in the response when it is listed, and should then also send Vary: Origin to show that the answer depends on the Origin header.4 The browser compares the header with the page's origin and gives the response to the script only on a match. A refused script gets a generic error without details; the reason appears only in the browser console.1
Requests a plain HTML form could already send, such as a GET or a POST with a form content type, go out directly. Other requests, for example a POST with a JSON or XML body or a custom header, are first announced by a preflight request:1
OPTIONS /doc HTTP/1.1
Origin: https://app.example.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 86400
Vary: OriginOnly if this answer allows the method and headers does the browser send the real request. Access-Control-Max-Age sets how many seconds the browser may reuse the answer; without it the default is 5 seconds.1
Credentials
By default a cross-origin fetch() carries no cookies or HTTP authentication. The calling code opts in with credentials: "include", and the browser then hands over the response only if it contains Access-Control-Allow-Credentials: true. The cookie is sent with the request either way; the header decides whether the page may read the answer.1 For such requests the server has to name an exact origin, because browsers refuse a response that combines * with credentials.4
Misconfigurations
Most CORS flaws come from servers that trust more origins than intended, often to make an integration work.2
| Setting | Effect |
|---|---|
Request Origin copied into the response, with credentials | Any website can read signed-in responses in a visitor's browser, including API keys and CSRF tokens.2 |
| Allow-list checked by prefix, suffix or loose regular expression | A rule meant for example.com also accepts attackerexample.com or example.com.attacker.net.2 |
null allowed | Sandboxed frames and data: or file: documents have the origin null, and any site can create one.4 |
* on data that is not public | Any site can read it. On an intranet, a page on the internet can use an employee's browser to read internal addresses.2 |
A trusted origin on plain http:// or with an XSS flaw | Whoever can inject script into the trusted origin can read the trusting site.2 |
Each of these settings switches off the same-origin policy for the site that sends it, which opens the way to attacks comparable to cross-site scripting and lets private data travel to the attacker.5
In CVE-2025-53092, the npm package @strapi/core shipped the first of these mistakes. A default Strapi installation copied any Origin into Access-Control-Allow-Origin and sent Access-Control-Allow-Credentials: true. The advisory, published on 16 October 2025, rated it 7.5 (High) in CVSS 3.1, and version 5.20.0 fixed it.6
Limits
CORS is enforced by the browser alone.7 The server receives and processes every request whatever its CORS headers say, and tools such as curl or another server ignore them.8 An API therefore still needs Authentication and Authorization of its own.8 The Origin header cannot be set by a script in the browser but can be forged by any other client, so it is not proof of who is calling.7 CORS also does not stop cross-site request forgery: a form on another site can still send a request with the visitor's cookies, and the defence is an unguessable token checked by the server.32
Configuration
A wildcard is acceptable only for a public API that anyone may use.7 Everything else gets an explicit list of exact origins. In Express, the cors package sends * when called without options, and origin: true repeats whatever origin arrives.8 An array of exact strings avoids both:
const cors = require('cors');
app.use(cors({
origin: ['https://app.example.com', 'https://admin.example.com'],
credentials: true,
}));The package also accepts regular expressions, and one such as /example\.com$/ accepts every origin that ends in example.com, including domains other people can register.82
Supabase Edge Functions called from a browser have to answer the preflight themselves. The withSupabase wrapper does this; without it, the function returns corsHeaders from npm:@supabase/supabase-js@^2/cors on the OPTIONS request and on every other response. The Supabase client sends its session token or API key in an authorization header rather than a cookie.9
Prompt for a coding agent
Find every place in this project that sets CORS headers: framework middleware such as the cors package, route handlers, edge or serverless functions, and hosting config files such as vercel.json, netlify.toml or nginx config. For each one, report the origins it allows and whether it allows credentials. Replace any setting that copies the request Origin back, uses origin: true, allows null, or matches origins with a prefix, suffix or unanchored regular expression with a fixed list of exact origins taken from an environment variable. Keep Access-Control-Allow-Origin: * only on routes that return public data without cookies, and never together with Access-Control-Allow-Credentials: true. Add Vary: Origin where an explicit origin is returned. List each file and line you changed.
In SecFlash
SecFlash reports these settings on the Security page: SF-SEC-111 when the app repeats any origin and allows credentials, SF-SEC-114 when it repeats any origin without credentials, SF-SEC-113 when it trusts the null origin, SF-SEC-112 when it pairs * with credentials, and SF-SEC-603 when an address answers with Access-Control-Allow-Origin: *. A hosting config file that sends * appears on the Cloud page as SF-CLD-801.
See also
- HTTP security headers
- Content Security Policy
- Session management
- Authorization
- Cross-site scripting
- Category: Security concepts
References
- a b c d e f "Cross-Origin Resource Sharing (CORS)". MDN Web Docs. Mozilla.
- a b c d e f g h i "Cross-origin resource sharing (CORS)". Web Security Academy. PortSwigger.
- a b c d "Same-origin policy". MDN Web Docs. Mozilla.
- a b c "Access-Control-Allow-Origin header". MDN Web Docs. Mozilla.
- back MITRE (11 December 2025). "CWE-942: Permissive Cross-domain Security Policy with Untrusted Domains". Common Weakness Enumeration.
- back GitHub Advisory Database (16 October 2025). "GHSA-9329-mxxw-qwf8: Strapi core vulnerable to sensitive data exposure via CORS misconfiguration". OSV.
- a b c "Testing Cross Origin Resource Sharing (WSTG-CLNT-07)". OWASP Web Security Testing Guide v4.2. OWASP Foundation.
- a b c d "cors middleware" (v2.8.6). Express.
- back Supabase (4 September 2026). "CORS (Cross-Origin Resource Sharing) support for Invoking from the browser". Supabase Docs.
External links
- Fetch Standard: CORS protocol, WHATWG
- HTML5 Security Cheat Sheet, OWASP Cheat Sheet Series