Skip to main content

What is Anti-Forgery and why is it required in ASP.NET Core?

Mid .NET Core
Quick Answer CSRF attacks forge requests from a malicious site using the victim's authenticated session. Anti-forgery prevents this by requiring a secret token only the legitimate server and browser share. ASP.NET Core validates the token on every form POST. Razor's
tag helper adds it automatically. APIs using JWT tokens in headers don't need anti-forgery (no cookie auth).

Answer

Anti-forgery tokens prevent CSRF attacks by validating a cookie token + form token pair. ASP.NET Core automatically validates tokens for unsafe HTTP verbs like POST.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice