CORS vs CSRF: Response Access and Forged Writes
By Ankit Jain · Updated
Understand why a blocked response does not prevent a forged state-changing request and how cookie sessions need dedicated CSRF defenses.
CSRF is a forged action carried out using a victim’s ambient authentication, such as a browser session cookie. CORS concerns cross-origin response access. A server must defend state-changing operations even if an attacker cannot read their response.
A blocked read does not undo a write
If a vulnerable endpoint accepts a simple form submission with an eligible session cookie, a malicious page may trigger a write. The response can be unreadable while the action has already happened. Moving the write from GET to POST is necessary design hygiene, but POST alone is not CSRF protection.
Keep dedicated defenses
Use your framework’s maintained CSRF protection for cookie-authenticated state-changing routes. Validate CSRF tokens, apply appropriate Origin/Referer validation, and use cookie protections as defense in depth. Keep GET and other safe methods free of state changes.
SameSite is about sites rather than exact origins. SameSite=Lax generally restricts cross-site cookie inclusion but allows qualifying top-level safe navigations; it is not a rule saying cookies accompany every navigation or never accompany cross-origin traffic. SameSite=None; Secure permits eligibility for cross-site use, subject to other cookie and browser rules.
Session cookie versus bearer token
A token explicitly supplied by application JavaScript is different from a cookie automatically attached by the browser. Evaluate how the endpoint obtains authentication. Do not disable CSRF because a site also uses CORS; the two controls address different parts of the request.
Verify in an authorized test environment
Confirm a state-changing cookie request without a valid CSRF token is rejected. Confirm an approved frontend with its token still works. Test actual application behavior, not merely the presence of CORS headers. XSS and stolen tokens are separate threats that can undermine these assumptions.
For Django, see CORS and CSRF configuration. Continue with credentials and CORS configuration risks.