Skip to main content

What is Anti-Forgery and why is it required?

Junior .NET Core
Quick Answer Anti-Forgery tokens prevent Cross-Site Request Forgery (CSRF) attacks where a malicious site tricks a user's browser into submitting a form to your app. ASP.NET Core generates a hidden form token and a cookie token. On form submission, it verifies both match. The [ValidateAntiForgeryToken] attribute or Razor form tag helpers handle this automatically.

Answer

Anti-forgery protection defends against Cross-Site Request Forgery (CSRF) attacks.

ASP.NET Core generates a pair of correlated tokens: one stored in a cookie and one embedded in the form. On POST, both must be present and valid. This ensures that state-changing requests originate from the legitimate site and user, not from a malicious third-party page.

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