The synchronizer token pattern defends against cross-site request forgery (CSRF) by requiring matching, user-specific antiforgery tokens through separate request channels: a cookie and a protected form field. section 29.2
A protected POST follows this sequence:
- The application generates unique tokens for the logged-in user. section 29.2
- One token is stored in a cookie, while another is rendered in the form. section 29.2
- The application compares both values and rejects the request if either is missing or they do not match. section 29.2
Razor Pages form
In ASP.NET Core Razor Pages, the Form Tag Helper automatically adds an antiforgery cookie and a hidden __RequestVerificationToken field to forms unless disabled. A forged site can cause the browser to send the cookie, but cannot read it to add the matching form token. section 29.2
