Skip to content

Commit 36c9dc5

Browse files
Copilotwadepickett
andauthored
Add CSRF protection warning for DisableAntiforgery() (#36660)
* Initial plan * Add antiforgery opt-out warning and update ms.date Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
1 parent 0a66d9b commit 36c9dc5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

aspnetcore/security/anti-request-forgery.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Discover how to prevent attacks against web apps where a malicious
77
monikerRange: '>= aspnetcore-3.1'
88
ms.author: tdykstra
99
ms.custom: mvc
10-
ms.date: 11/16/2023
10+
ms.date: 01/22/2026
1111
uid: security/anti-request-forgery
1212
---
1313
# Prevent Cross-Site Request Forgery (XSRF/CSRF) attacks in ASP.NET Core
@@ -321,6 +321,15 @@ In the preceding code, posts to:
321321

322322
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MyAntiForgery/Program.cs" id="snippet_post":::
323323

324+
> [!WARNING]
325+
> Calling `.DisableAntiforgery()` disables cross-site request forgery (CSRF) protection for the endpoint. This should only be used when an endpoint is not vulnerable to CSRF attacks, such as:
326+
>
327+
> * Endpoints that are not callable from a browser (for example, internal APIs)
328+
> * Endpoints secured with non-cookie-based authentication (for example, bearer tokens or API keys)
329+
> * Internal or infrastructure endpoints that do not rely on user cookies
330+
>
331+
> Do **not** disable antiforgery validation for browser-accessible endpoints that rely on cookies for authentication or that process user-submitted form data, as this exposes your application to CSRF attacks.
332+
324333
A POST to:
325334

326335
* `/todo` from the form generated by the `/` endpoint succeeds because the antiforgery token is valid.

0 commit comments

Comments
 (0)