An application embeds an anti-CSRF token in each form, yet a forged cross-site POST succeeds. The server only checks that a token field is present, not its value. What is the best fix?
Show the answer
Correct answerD. Compare the submitted token to the one bound to the user's session
AWhy not this: A shorter session narrows the attack window but leaves forged requests valid while the session lasts.
BWhy not this: Blocking internal destinations mitigates SSRF, which is a server-originated request, not a forged browser request.
CWhy not this: Output encoding stops XSS; the flaw here is missing token validation, not script injection.
DWhy this is right: Matching the token to the session value means a forged request, lacking the secret, is rejected.
A synchronizer token only works if the server verifies that the submitted value matches the secret tied to the session, which an attacker's forged page cannot know. Shortening the session only narrows the window; forged requests still succeed while the session is active.