Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4121702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:23:08+00:00 2026-05-20T23:23:08+00:00

The AntiForgeryToken is used to prevent CSRF attacks, however the links on MSDN don’t

  • 0

The AntiForgeryToken is used to prevent CSRF attacks, however the links on MSDN don’t give me much insight to what exactly the AntiForgeryToken does, or how it works, or why things are done the way they are.

From what I gather, it creates a hash inside a web page and a cookie. One or both of them use the hashed IPrincipal.Name, and use symmetric encryption.

Can anyone shed light as to:

  1. How the AntiForgeryToken works internally
  2. What should it be used to protect
  3. What should it NOT be used to protect
  4. What is the reasoning behind the implementation choices for #1 above?
    • Example:
      • is the implementation safe from “DoubleSubmit” cookies and other common vulnerability
      • Are there implementation issues if the user opens multiple tabs
      • What makes MSFT’s implementation different from the one available at SANS
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:23:09+00:00Added an answer on May 20, 2026 at 11:23 pm

    Okay, here is my best shot.

    1) Internally, mvc uses RNG crypto methods to create a 128 bit string to act as the XSRF token. This string is stored in a cookie as well as in a hidden field somewhere on the form. The cookie name seems to be in the form of __RequestVerificationToken + a base 64 encoded version of the application path(server side). The html part of this uses the AntiForgeryDataSerializer to serialize the following pieces of data
    – salt
    – value(the token string)
    – the ticks of the creation date
    – the username (seems like Context.User)

    The validate method basically deserializes the values out of the cookie and that of the form and compares them based on the values (salt/value/ticks/username).

    2/3) I would think this discussion is more for when to use XSRF tokens and when not to. In my mind, you should use this on every form (I mean why not). The only thing I can think of that this doesn’t protect is if you have actually hit the form in question or not. Knowing the base64 encoding of the app name will allow the attacker to be able to view the cookie during the XSRF attack. Maybe my interpretation of that is incorrect.

    4) Not sure exactly what you are looking for here? I guess I would have built a mechanism where I would try and store the XSRF token in the session (if one was already available) and if not, then try the cookie approach. As for type of crypto used, I found this SO artcile.
    Pros and cons of RNGCryptoServiceProvider

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that the AntiForgeryToken feature in ASP.NET MVC does prevent cross-site attacks. However,
I would like to use the AntiForgeryToken function but the AcceptVerbs post does not
I have implemented in my app the mitigation to CSRF attacks following the informations
I have the following razor code: <form id=logon action=/security/dev method=get> @Html.AntiForgeryToken() @Html.EditorFor(x => x.UserName)
Using AntiForgeryToken requires each request to pass a valid token, so malicious web pages
i read about how to use the <@Html.AntiForgeryToken()> to generate an encrypted value in
I am interested why isn't AntiForgeryToken included in every ASP.NET MVC form by default?
I know that Stack Exchange sites do not use the ASP.NET MVC built-in @Html.AntiForgeryToken()
I'm trying to use the Html.AntiForgeryToken in ASP.NET MVC under Mono (XSP) and it
I’m having problems with the AntiForgeryToken in ASP.Net MVC. If I do an iisreset

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.