Remediation
CSRF Tokens
Remediation
As a defense, the token approach remains one of the most broadly applicable controls on this list. Unlike SameSite, it does not depend primarily on browser cookie policy to prevent the attack. Instead, it requires the request to contain an additional unpredictable value that an attacker-controlled origin cannot normally read or obtain. The browser may still send the victim's session cookie with a forged request, but without the corresponding valid CSRF token, the server rejects the request.
Its main cost is implementation complexity: tokens must be generated securely, associated with the appropriate session or request, validated correctly, and enforced consistently across every state-changing endpoint.
The central principle is: SameSite limits when the browser sends the victim's credentials; a CSRF token gives the server an independent value with which to verify that a state-changing request is legitimate. The token is effective only when its validation is correct and consistently enforced.