What security risks does an overly permissive CORS policy (like AllowAnyOrigin with credentials attempted, or reflecting the Origin header) introduce?
Short answer
While AllowAnyOrigin combined with AllowCredentials is blocked by the spec itself, a common but dangerous workaround some developers implement is dynamically 'reflecting' whatever Origin header the request sends back as the Access-Control-Allow-Origin value (effectively allowing…
Advertisement
AModel answer
While AllowAnyOrigin combined with AllowCredentials is blocked by the spec itself, a common but dangerous workaround some developers implement is dynamically 'reflecting' whatever Origin header the request sends back as the Access-Control-Allow-Origin value (effectively allowing every origin while still technically satisfying the credentials requirement) -- this defeats CORS's entire security purpose, allowing any malicious website to make authenticated cross-origin requests using a logged-in user's cookies, a serious CSRF-adjacent vulnerability.
// DANGEROUS anti-pattern: reflecting any origin defeats CORS's purpose
policy.SetIsOriginAllowed(origin => true) // allows literally ANY origin
.AllowCredentials();
// SAFE: explicit allowlist of known, trusted origins only
policy.WithOrigins("https://app.mycompany.com", "https://admin.mycompany.com")
.AllowCredentials();Real-world example
A security audit flags a CORS configuration using SetIsOriginAllowed(_ => true) combined with AllowCredentials as a critical vulnerability, since it effectively allows any malicious website to make authenticated API calls using a victim's session cookies.
Likely follow-ups
- How would an attacker actually exploit an overly permissive CORS + credentials configuration?
- What's the safe way to support multiple known frontend origins?
Related topics