aspnet-404869-security-considerations-prevent-csrf.md
In Cross-Site Request Forgery (CSRF) attacks, a threat actor tricks an authenticated user into executing unauthorized commands.
Use anti-forgery tokens to protect your application from CSRF attacks. These tokens work as follows:
To use anti-forgery tokens in your application callbacks:
Make certain that the application references the System.Web.WebPages.dll assembly.
Create a master page that generates an AntiForgery token:
During master page initialization, add a handler for the Page.PreLoad event:
In the event handler, call the Validate method to check whether the token is valid:
The following DevExpress ASP.NET Web Forms components implement custom request processing:
Internal requests from these controls are processed by the DevExpress HTTP module instead of the standard page handler. As a result, an AntiForgery.Validate() call from Page_PreLoad is not executed for these requests. You must apply the additional steps below.
Note
The following steps supplement, but do not replace, anti forgery token validation for callbacks described above. Implement both mechanisms for CSRF protection.
Make certain that the master page generates an anti-forgery token:
Add a client function that injects the token into the RequestVerificationToken HTTP request header.
Pass the function name to the control’s BeforeSend property to add the token to all internal HTTP requests.
Implement IHttpModuleSubscriber to validate the RequestVerificationToken HTTP request header against the anti forgery cookie token. Reject all unsafe requests that fail validation.
Register the AntiforgeryOfficeHttpModuleSubscriber at application startup so the DevExpress module can invoke it for matching requests.