What is the Html.AntiForgeryToken helper function for?

后端 未结 5 957
遥遥无期
遥遥无期 2021-02-05 18:51

Can somebody tell me more details about it?

5条回答
  •  迷失自我
    2021-02-05 19:25

    Using AntiForgeryToken helps mitigate against cross-site request forgery attacks.

    When you use it, your form will contain a hidden field and a corresponding cookie will also be set in the browser.

    Then, when the form is submitted, the hidden field is checked against the cookie value (assuming that ValidateAntiForgeryTokenAttribute is used): if the field and the cookie match then the form post is probably genuine; if they don't then it's probably not. (An attacker attempting a CSRF attack might be able to forge the hidden field, but they shouldn't be able to also forge the corresponding cookie value.)

提交回复
热议问题