Course contentsShow
← Security
Lesson 876 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

Access-Control-Allow-Origin Misconfigurations

Common mistakes with wildcard origins, null origins, and dynamic origin reflection vulnerabilities.

Access-Control-Allow-Origin Misconfigurations

What you'll learn: You'll understand the most common and dangerous ways developers accidentally open security holes when configuring CORS origins.

The Core Problem

When implementing CORS, developers must configure the Access-Control-Allow-Origin header to specify which origins can access their resources. However, several common mistakes turn this protective mechanism into a vulnerability:

1. Wildcard with Credentials The most tempting mistake is setting Access-Control-Allow-Origin: * while also allowing credentials. This seems convenient but browsers explicitly block it—so it doesn't work. However, developers sometimes try workarounds that create vulnerabilities.

2. Dynamic Origin Reflection Instead of using a wildcard, some servers read the incoming Origin header and blindly echo it back:

Request: Origin: https://evil.com
Response: Access-Control-Allow-Origin: https://evil.com

This is worse than a wildcard—it lets any origin make credentialed requests. Think of it like a bouncer who checks your ID, then lets you in no matter what it says.

3. Trusting Null Origins The null origin occurs in sandboxed iframes and certain file:// contexts. Some developers whitelist it thinking it's safe, but attackers can easily generate requests with Origin: null:

Response: Access-Control-Allow-Origin: null

This allows any attacker-controlled sandboxed iframe to make credentialed requests.

4. Weak Subdomain Validation Checking if an origin "contains" your domain without proper validation:

  • Intended: https://app.example.com
  • Exploited: https://app.example.com.evil.com or https://evilapp.example.com

Why This Matters

These misconfigurations bypass Same-Origin Policy protections, allowing attackers to steal sensitive data from authenticated users—essentially creating CSRF vulnerabilities with response access.

Key Takeaway: Never blindly reflect the Origin header, whitelist null, or use loose string matching. Always validate origins against an explicit allowlist of exact, trusted domains.