Learn how Cross-Origin Resource Sharing (CORS) works, how it breaks, and how attackers exploit misconfigured origins.
For security, browsers restrict scripts running on one origin from accessing data on another origin. Origins are defined as: scheme://domain:port
This prevents malicious sites from stealing your credentials and data.
CORS (Cross-Origin Resource Sharing) is the controlled mechanism that *allows* cross-origin requests when configured correctly. The server explicitly tells the browser: "Yes, I allow requests from this other origin."
CORS is implemented via HTTP headers:
Developers often misunderstand CORS and configure it too permissively:
1. Attacker hosts malicious page: https://attacker.com/steal.html
2. Victim visits attacker site while logged into vulnerable app: The victim's browser still has valid session cookies for vulnerable-app.com
3. JavaScript sends cross-origin request:
4. Browser checks CORS headers: If vulnerable-app returns "Access-Control-Allow-Origin: *" or echoes attacker.com, it allows the request
5. Attacker exfiltrates data: Victim's sensitive data (profile, messages, financial info) sent to attacker
Facebook (2013): Misconfigured CORS allowed anyone to read user data via JavaScript
Yahoo (2014): CORS allowed cross-origin access to sensitive APIs
Many startups: Reflective Origin Echo โ Developers echo the Origin header without validation
Lab 00 - Origin Reflection: Exploit a server that echoes back the Origin header for credentials=true
Lab 10 - Weak Validation Bypass: Bypass substring-based origin validation