}
‘Then validete it at the method or preferably the controller level:
[HttpPost]
[ValidateantiforgeryToken]
public ActionResult LogOff()
Make sure the tokens are remaved completely for invalidation on logout.
///
//] SECURE: Remove any remaining cookies including Anti-CSRF cookie
//1
public void RemoveAntiForgeryCookie(Gontroller controller)
4
stringl] allCookies = controller Request .Cookies.AlIKeys;
foreach (string cookie in aliCookies)
4
if (controller.Response.Cookies[cookie] != null &
cookie = "__RequestVerificetionToke
{
cont roller .Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1) ;
}
+
+
USING NET CORE 2.0 OR LATER
‘ntps:ifcheatshectseries.owasp.oricheatsheets/DotNet_Securty_Cheat_Sheethtml 1923972322, 07 AM DotNet Securty - OWASP Cheat Sheet Series
Starting with NET Core 20itis possible to automatically generate and verify the antiforgery token.
I youare using tag:helpers, which is the default for most web project templates, then ll forms will
‘automatically send the anti-forgery token. You can check f tag-helpers are enabled by checking if
yourmain _Viewinports.cshtnl file contains:
@addTagHelper *, Microsoft.AspNetCore.Mvc. TagHelpers.
THtrlHelper .SeginForm also sends anti-forgery-tokens automatically.
Unless you ate usingtag-helpers or THtmHelper .BeginFerm You must use the requisite helper on
formsas seen here: