Skip to content

Commit 6d06a66

Browse files
security: add global AutoValidateAntiforgeryToken filter
Replaces TODO comment with explicit AddControllersWithViews registration that applies AutoValidateAntiforgeryTokenAttribute globally. Ensures all MVC controller POST/PUT/DELETE actions require a valid antiforgery token by default, providing defense-in-depth against CSRF even if individual actions are not annotated.
1 parent f2643a6 commit 6d06a66

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

EssentialCSharp.Web/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ private static void Main(string[] args)
232232
throw new NotSupportedException("The default UI requires a user store with password support.");
233233
});
234234

235-
//TODO: Implement the anti-forgery token with every POST/PUT request: https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery
235+
builder.Services.AddControllersWithViews(options =>
236+
{
237+
options.Filters.Add(new Microsoft.AspNetCore.Mvc.AutoValidateAntiforgeryTokenAttribute());
238+
});
236239

237240
if (!builder.Environment.IsDevelopment())
238241
{

0 commit comments

Comments
 (0)