CORS Misconfiguration
CORS misconfigurations allow malicious websites to make authenticated cross-origin requests and read the responses — effectively bypassing the Same-Origin Policy. When combined with sensitive API endpoints, this leads to account takeover and data theft.
CORS Basics
Browsers enforce the Same-Origin Policy (SOP): JavaScript on attacker.com can’t read responses from target.com. CORS is the mechanism that lets servers explicitly allow certain cross-origin requests.
The server controls this via response headers:
|
If ACAO is *, credentials can’t be included. The dangerous pattern is when both headers are set but ACAO is dynamically generated from the Origin header.
Testing for Vulnerabilities
Add an Origin header to requests:
|
Vulnerability Types
1. Reflected Origin
The server copies the Origin header directly into Access-Control-Allow-Origin:
|
PoC exploit:
|
2. Null Origin
Server allows Origin: null. This is triggered by:
- Sandboxed iframes
- Local HTML files
data:URIs- Redirected requests
|
3. Prefix/Suffix Trust
Server checks only that origin contains the target domain:
|
Bypass:
|
4. Trusted Subdomain Takeover
Server trusts all subdomains: *.target.com. If any subdomain can be taken over:
|
Find dangling CNAMEs, unclaimed S3 buckets, etc. on *.target.com subdomains, claim them, host the CORS exploit there.
5. HTTP → HTTPS Trust
Server trusts the HTTP version of its own origin:
|
If you can MitM the victim’s HTTP connection, inject your exploit.
CORS with Private Networks (New Spec)
Chrome now enforces Private Network Access (PNA). Test with:
|
If the server responds with Access-Control-Allow-Private-Network: true, internal network requests may be permitted.
Exploiting Pre-flight Bypass
For “simple” requests (GET, POST with standard content types), no pre-flight is sent. This means CORS misconfiguration exploits work without pre-flight approval for:
|
For POST with JSON, you’d normally need a pre-flight. Bypass: use text/plain or application/x-www-form-urlencoded if the server accepts it.
Full Account Takeover PoC
|
Automation
|
Remediation
- Maintain an explicit allowlist of trusted origins — never reflect the
Originheader directly. - Don’t use
Access-Control-Allow-Origin: *with credentials. - Avoid trusting
nullorigin in production. - Validate the full origin string, not a prefix or substring.
- Use the
SameSitecookie attribute as defense-in-depth.
Discussion
Leave a comment · All fields required · No spam
No comments yet. Be the first.