c# - Is ValidateAntiForgeryToken autoimplemented with POST? -


i'm reading post considered secure , no, , should implement [validateantiforgerytoken] in every action of every controller.

the question is: need use [validateantiforgerytoken] data annotation when use [post]?

it's off default.
there's reason this. not every post has come form (especially true since question tagged asp.net-core)

you should decorate controller action [validateantiforgerytoken]

[validateantiforgerytoken] public iactionresult post(model model) {     // ... etc } 

if you're using form tag helper, automatically add anti forgery token you, <form> markup.

the markup generated like:

<form action="/mycontroller" method="post">     <input name="__requestverificationtoken" type="hidden" value="fhtffhkknsdfhyazftn6c4ybzamsewg0srqluqqloi/oijoijoijojhishg" />     <!-- rest of form here --> </form> 

note: can manually enable/disable __requestverificationtoken generation using form helper tags:

<form  asp-controller="mycontroller"   asp-action="myaction"   asp-antiforgery="false"   method="post"> 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -