If your website has an API, a customer portal or a dashboard that loads data from another of your domains, a browser feature called cross-origin resource sharing (CORS) is probably involved. PortSwigger's Web Security Academy describes CORS as a browser mechanism that allows controlled access to resources outside a given domain, extending and adding flexibility to the same-origin policy. This article answers one question for a site owner: which CORS settings turn that controlled access into a data leak, and what should you ask your developer about them?
What CORS is and why a poorly configured policy is a risk
To see why CORS matters, start with the rule it relaxes. According to PortSwigger, the same-origin policy was defined in response to potentially malicious cross-domain interactions, such as one website stealing private data from another. It generally lets a domain send requests to other domains but not read the responses. That last part is the protection: another website may make a visitor's browser send a request to your site, but it normally cannot read what your site sends back.
CORS is how a server tells the browser to make an exception. PortSwigger explains that the protocol uses a suite of HTTP headers that define trusted web origins and related properties, such as whether authenticated access is permitted. In other words, your server's response headers decide which other sites may read your responses, and whether they may do so while the visitor is logged in.
The risk comes from how those exceptions are written. PortSwigger notes that CORS provides potential for cross-domain attacks if a website's CORS policy is poorly configured and implemented. It also states plainly that CORS is not a protection against cross-origin attacks such as cross-site request forgery (CSRF). So adding CORS headers never makes a site safer by itself; the question is only whether the exceptions you grant are narrow enough.
Sources: portswigger.net [1]
The two headers that decide how much is exposed
Two response headers carry most of the risk. The first is Access-Control-Allow-Origin, which names who may read the response. MDN lists a wildcard value, *, for requests without credentials, and states that trying to use the wildcard with credentials results in an error. MDN also describes the alternative: the header specifies a single origin, and if the server supports clients from several origins, it must return the origin of the specific client making the request.
The second is Access-Control-Allow-Credentials. MDN explains that this header tells browsers whether the server allows credentials to be included in cross-origin requests. Credentials here means cookies, TLS client certificates, or authentication headers containing a username and password, which in practice is the visitor's logged-in session. MDN notes that by default these credentials are not sent in cross-origin requests.
The browser enforces this. For a non-preflighted request, MDN says the request includes credentials, and if the server's response does not set Access-Control-Allow-Credentials to true, the browser reports a network error. The only valid value is true, and MDN advises that if you do not need credentials you should omit the header entirely rather than set it to false.
For a site owner, the practical reading is this: a response that names another origin and also allows credentials is letting that origin read what a logged-in visitor would see. PortSwigger's example of a dangerous response pairs exactly these two headers, and explains that with credentials allowed the cross-origin requests can include cookies and so are processed in-session. That combination deserves the closest review on any page that shows account data, API keys or tokens.
Sources: developer.mozilla.org [2] · developer.mozilla.org [3] · portswigger.net [1]
Mistake 1: echoing back whatever origin the request claims
The most damaging pattern PortSwigger describes is a shortcut. Keeping a list of allowed domains takes ongoing effort, and mistakes in it can break functionality, so some applications take the easy route of effectively allowing access from any other domain. One way they do this is by reading the Origin header from the incoming request and simply repeating it in the response as the allowed origin.
The consequence is stark. PortSwigger states that because such an application reflects arbitrary origins in Access-Control-Allow-Origin, absolutely any domain can access resources from the vulnerable domain. If the response contains sensitive information such as an API key or CSRF token, an attacker's page could retrieve it. Combined with credentials being allowed, this means a hostile website a logged-in customer happens to visit can read that customer's data from your site.
The correct approach, as MDN describes it, is an explicit check rather than an echo. Limiting Access-Control-Allow-Origin to a set of allowed origins requires server-side code that reads the Origin request header, compares it to a list of allowed origins, and only if the value is on that list sets Access-Control-Allow-Origin to the same value. The difference between the safe and unsafe versions is a single comparison against a list, which is exactly why it is easy to skip and worth asking about.
Sources: portswigger.net [1] · developer.mozilla.org [2]
Mistake 2: allowlists that match too loosely
Having an allowlist is not the end of the story. PortSwigger reports that mistakes often arise when implementing CORS origin whitelists. Some organizations decide to allow access from all their subdomains, including future subdomains that do not yet exist, and some applications allow other organizations' domains along with their subdomains.
The problem is in how those broad rules get written. According to PortSwigger, such rules are often implemented by matching URL prefixes or suffixes, or with regular expressions, and any mistake in the implementation can grant access to unintended external domains. Its examples are easy to picture. If an application trusts every domain ending in normal-website.com, an attacker might gain access by registering hackersnormal-website.com. If it trusts every domain beginning with normal-website.com, an attacker might use normal-website.com.evil-user.net.
For a business, the lesson is that a rule which looks like it means our own domains may in fact mean anything with our name in it. MDN's description of the safe pattern, comparing the Origin value against a list of allowed origins, points toward listing exact origins rather than patterns. If your developer uses prefix, suffix or pattern matching, ask them to show you which origins it accepts and why a lookalike domain cannot pass.
Sources: portswigger.net [1] · developer.mozilla.org [2]
Mistake 3: trusting the null origin
Browsers sometimes send the value null in the Origin header. PortSwigger lists cross-origin redirects, requests from serialized data, requests using the file: protocol and sandboxed cross-origin requests as situations where this can happen. It also notes that some applications whitelist the null origin to support local development, which is how this setting tends to slip into production.
MDN is direct that the null value should not be used. It explains that many browsers will grant documents with a null origin access to a response carrying Access-Control-Allow-Origin: null, and any origin can create a hostile document with a null origin. PortSwigger describes the result: an attacker can use various tricks to generate a request with null in the Origin header, which satisfies the whitelist and leads to cross-domain access.
If a null entry exists only because it helped during development, it is worth asking whether it is still present on the live site. The guidance from MDN leaves no ambiguity: avoid the null value for this header.
Sources: portswigger.net [1] · developer.mozilla.org [2]
Even a correct allowlist extends trust to the sites on it
A tidy list of exact origins still carries risk, because every origin on it becomes part of your security. PortSwigger points out that even correctly configured CORS establishes a trust relationship between two origins. If your site trusts an origin that is vulnerable to cross-site scripting (XSS), an attacker could exploit that XSS to inject JavaScript which uses CORS to retrieve sensitive information from your site. A forgotten marketing subdomain or an old microsite on the list can therefore become the way in.
The same applies to how trusted origins are served. PortSwigger describes an application that rigorously uses HTTPS but whitelists a trusted subdomain served over plain HTTP. In that situation, an attacker in a position to intercept a victim's traffic can exploit the CORS configuration to compromise the victim's interaction with the application. An http:// entry in an otherwise https:// list is therefore a weak link worth questioning.
This is also why CORS problems are common rather than exotic. PortSwigger observes that many modern websites use CORS to allow access from subdomains and trusted third parties, and that implementations may contain mistakes or be overly lenient to ensure that everything works, which can result in exploitable vulnerabilities. The pressure to make an integration work is exactly the moment a policy tends to get loosened.
Sources: portswigger.net [1]
Questions to ask your developer about your CORS policy
You do not need to read server code to hold a useful conversation about CORS. The sources above translate into a short set of review questions you can put to whoever maintains your site or API.
First, ask how the allowed origin is chosen. MDN describes the safe pattern as server-side code that compares the Origin request header to a list of allowed origins and returns it only if it is on that list. If the answer is that the server returns whatever origin the request sends, that is the reflection pattern PortSwigger shows letting absolutely any domain access resources.
Second, ask which endpoints allow credentials and why. MDN advises that if you do not need credentials you should omit Access-Control-Allow-Credentials entirely rather than setting it to false. Endpoints that serve public data have no reason to read a visitor's session.
Third, ask whether null appears anywhere in the allowed list. MDN says the null value for Access-Control-Allow-Origin should be avoided.
Fourth, ask how caching is handled when a specific origin is returned. MDN states that when a response carries an explicit origin rather than the wildcard, it should also include a Vary response header with the value Origin, to tell browsers that responses can differ based on the Origin request header.
Finally, ask that CORS not be relied on for CSRF defense. PortSwigger states that CORS is not a protection against cross-origin attacks such as CSRF, so form and state-changing requests need their own protection.
Sources: developer.mozilla.org [2] · portswigger.net [1] · developer.mozilla.org [3]
What this article does not cover
This is a conceptual guide to the settings that create CORS risk and the questions that bring them to light. It does not include a step-by-step testing procedure, server configuration snippets for particular platforms, or guidance on preflight requests beyond what is described above. It also leaves out attacks on internal networks that do not rely on credentials. The questions in the previous section are a starting point for a conversation with your developer, not a full security review of your site.
Questions and answers
Which CORS settings can expose my website's data, and what should I ask my developer?
which CORS settings turn that controlled access into a data leak, and what should you ask your developer about them?
Why is reflecting the Origin header in Access-Control-Allow-Origin dangerous?
absolutely any domain can access resources from the vulnerable domain
Should Access-Control-Allow-Origin ever be set to null?
avoid the null value for this header
Does CORS protect against CSRF?
CORS is not a protection against cross-origin attacks such as cross-site request forgery (CSRF)
Should I set Access-Control-Allow-Credentials to false if I don't need it?
you should omit the header entirely rather than set it to false
Pick one page on your site that shows customer data and ask your developer the questions above about it this week. To go further, read our guides on missing website security headers and input validation for website owners, or run a free website security scan.

