CORS Configuration Risks: Approved Origins and Private Data
By Ankit Jain · Updated
Distinguish unsafe credentialed origin reflection from legitimate public API permission, and test origin boundaries.
A CORS policy decides which webpages may read an API response in a user’s browser. The risk depends on the response data, authentication, and the origins you approve.
Unsafe credentialed origin reflection
Reflecting any incoming Origin together with Allow-Credentials: true can let an attacker’s page read private responses using eligible victim credentials. Use an explicit approved-origin list and enable credentialed access only where the integration needs it. Unanchored suffix checks can accidentally approve attacker-controlled domains.
Wildcard permission is not always a vulnerability
Allow-Origin: * can be intentional for public, noncredentialed data. Combining it with include-mode requests causes a browser permission failure; it does not automatically reveal cookie-authenticated data. The dangerous repair is to replace it with unrestricted origin reflection and credentials permission.
CORS is not an API access-control firewall. A non-browser client can make its own requests. Authentication, authorization, abuse controls, and CSRF defenses remain necessary.
Other boundaries to check
- Do not approve null indiscriminately; unrelated opaque origins can share that serialization.
- Approve only managed origins. A compromised or abandoned subdomain can undermine a broad allowlist.
- Expose only response headers the frontend needs. Never place secret values in responses solely because you believe CORS will hide them.
- Avoid shared caching of private data. Vary: Origin is not a substitute for user-aware cache policy.
Test behavior, not just configuration
In an authorized test environment, compare an approved and unapproved origin against both public and authenticated endpoints. Check that private endpoints still enforce authorization. Confirm the browser cannot read private data from an unapproved origin, and separately confirm state-changing cookie requests have CSRF protection.
Use framework middleware with deliberate settings. See credentials, CSRF, and cache ownership.