ASP.NET MVC - does AntiForgeryToken prevent the user from changing posted form values?

前端 未结 1 1751
走了就别回头了
走了就别回头了 2020-12-20 08:56

I understand that the AntiForgeryToken feature in ASP.NET MVC does prevent cross-site attacks.

However, does it prevent from changing form values before POST?

相关标签:
1条回答
  • 2020-12-20 09:18

    AntiForgeryToken prevents a malicious site to trick a user to a form that looks the same as the original and post it to the original site. It does not prevent the scenario you are describing. Here's how an attacker could proceed in order to circumvent the token:

    1. The hacker sends a GET request to the form.
    2. He reads the value of the cookie generated by the AntiForgeryToken
    3. He POSTs to the url handling the form action by sending the cookie, the RequestVerificationToken hidden field which has the same value as the cookie and the modified entity ID.

    As you can see the only difference to as if you haven't used AntiForgeryToken is that the hacker needs to send an additional GET request to read the value of the token.

    There's absolutely no way to prevent an attacker from modifying the value of a hidden field other than verifying that the user who submitted the form (I suppose that in order to vote the user has to be authenticated) is not the owner of the entity ID he is voting for.

    0 讨论(0)
提交回复
热议问题