CORS Misconfiguration Vulnerabilities
On this page
Learning Objective
Recognize the CORS misconfiguration patterns that recur across real vulnerability disclosures, understand how each is discovered and exploited, and apply a review checklist that catches them before they ship.
Concept Explanation
CORS misconfigurations are unusually common in production for three structural reasons. First, CORS failures are loud and functional failures are silent: a policy that is too tight breaks the application immediately and visibly, while a policy that is too loose works perfectly and shows no symptom at all. The feedback loop therefore pushes teams toward permissiveness. Second, the header takes a single value, so anything beyond one front end requires dynamic computation, which is where the bugs live. Third, the configuration frequently sits in a gateway, proxy, or framework middleware that nobody reviews with the same rigor as application code.
The recurring patterns are worth memorizing as a checklist. Unconditional reflection with credentials, covered in the previous lesson, is the most severe. Trusting null is the second most common, because it appears in configuration as a narrow exception for an unusual edge case while actually being reachable by any attacker through a sandboxed iframe. Allowing any subdomain via a suffix or pattern match is third, and it is dangerous because it converts an XSS or takeover on any subdomain, including a marketing site, a status page, or a dangling DNS record, into full read access to the credentialed API.
A fourth pattern is CORS on a non-production or internal origin that is also reachable in production, for example a policy that allows http://localhost:3000 so developers can work locally. Any page can navigate a user to a URL that resolves to localhost, and in some historical configurations a DNS entry pointing at 127.0.0.1 makes an attacker-controlled hostname resolve locally, so a localhost allowance is not the private convenience it appears to be. A fifth is granting CORS access to endpoints that were never designed to be read cross-origin at all, typically because a middleware applies the policy globally rather than per route.
Discovery is straightforward, which is why these findings are so plentiful in bug bounty programs. A tester sends a request with a fabricated Origin header and inspects the response: if Access-Control-Allow-Origin echoes the fabricated value and Access-Control-Allow-Credentials is true, the finding is confirmed in a single request. Variations substitute a subdomain of the attacker's domain, a suffix-matched lookalike, the null value, and a scheme downgrade to probe each of the patterns above. Automated scanners run the whole matrix in seconds.
The remediation checklist is correspondingly short. Maintain an exact-match allowlist of full origins, defined in one place and reviewed like any other access control. Enable credentials only on the specific routes that require them, never globally. Never allow null and never allow localhost in a production configuration. Apply CORS per route rather than as a blanket middleware, so that adding a sensitive endpoint does not silently inherit a permissive policy. Send Vary: Origin whenever the value is computed. And write a test that asserts a fabricated origin is rejected, because that is the single check that would have caught almost every disclosure in this category.
| Misconfiguration | How it is found | Impact |
|---|---|---|
| Unconditional origin reflection with credentials | Send a fabricated Origin and see it echoed back | Any site the victim visits reads their authenticated data |
| Access-Control-Allow-Origin: null with credentials | Send Origin: null from a sandboxed iframe | Same impact, reachable by any attacker page |
| Suffix or pattern-matched subdomains | Try evil-example.com and example.com.evil.net | Any subdomain XSS or takeover becomes full API read access |
| localhost allowed in production | Inspect the configuration or probe the origin | A local or DNS-controlled origin gains credentialed read access |
| Global middleware instead of per-route | Compare CORS headers across sensitive routes | New sensitive endpoints silently inherit a permissive policy |
Worked Example: A Three-Request Audit of Any API
The probes below are what a reviewer or an attacker runs first. Each one takes a second and each one confirms or eliminates a specific pattern from the checklist above.
# PROBE 1 - unconditional reflection
$ curl -sI https://api.example.com/v1/me -H 'Origin: https://evil.example' \
| grep -i access-control
Access-Control-Allow-Origin: https://evil.example # <-- confirmed
Access-Control-Allow-Credentials: true # <-- critical
# PROBE 2 - the null origin
$ curl -sI https://api.example.com/v1/me -H 'Origin: null' | grep -i access-control
Access-Control-Allow-Origin: null
Access-Control-Allow-Credentials: true
# Reachable from: <iframe sandbox="allow-scripts" srcdoc="<script>..."></iframe>
# PROBE 3 - suffix and lookalike matching
$ curl -sI https://api.example.com/v1/me -H 'Origin: https://evil-example.com'
$ curl -sI https://api.example.com/v1/me -H 'Origin: https://example.com.evil.net'
# The regression test every API should have:
test('rejects a fabricated origin', async () => {
const res = await request(app).get('/v1/me')
.set('Origin', 'https://evil.example');
expect(res.headers['access-control-allow-origin']).toBeUndefined();
});Real-World Examples
- PortSwigger's 2016 research catalogued the null-origin trap as a distinct finding class: developers add null to an allowlist because it appears in logs from redirects and sandboxed content and looks like a harmless internal case, not realizing that any attacker can produce a null origin on demand by loading their payload inside a sandboxed iframe, which makes allowing null functionally equivalent to allowing every origin.
- Subdomain-scoped CORS policies have repeatedly converted low-severity findings into critical ones in public bug bounty reports: an allowlist matching any subdomain of a company's domain means an XSS on a marketing microsite, a status page, or a takeoverable dangling DNS record grants credentialed read access to the production API, which is why triage teams routinely escalate subdomain takeovers at organizations known to use pattern-matched CORS.
Review Questions & Answers
The feedback is asymmetric. A policy that is too restrictive breaks the application immediately and visibly, generating bug reports and pressure to loosen it, while a policy that is too permissive works flawlessly and produces no symptom whatsoever. Every incentive during development pushes toward widening the policy until things work, and nothing pushes back, so unless a review or an automated test specifically checks for over-permissiveness, the drift is one-directional.
Because null is not an identity, it is what the browser sends when the requesting context has an opaque origin, and an attacker can create one at will by putting their script inside a sandboxed iframe without allow-same-origin. There is no way for the server to distinguish a null origin coming from a legitimate internal redirect from one coming from an attacker's sandboxed frame, so the allowance grants read access to anyone who takes that one extra step.
It escalates it dramatically. Without such a policy, a takeover of a marketing subdomain is a phishing and reputation problem. With it, the attacker-controlled subdomain is on the API's credentialed allowlist, so any script they host there can issue authenticated fetches to the production API on behalf of any logged-in visitor and read the responses. A finding that would be rated low or medium becomes a path to reading arbitrary user data.
Because the policy then applies to every endpoint that exists now and every endpoint anyone adds later, including sensitive ones nobody intended to expose cross-origin. A permissive policy written for one public read-only route silently extends to a newly added admin or export endpoint, and there is no point in the development process at which anyone is prompted to reconsider it. Per-route configuration forces the decision to be made, and reviewed, each time.