antiforgerytoken

How does ValidateAntiForgeryToken fit with Web APIs that can be accessed via web or native app?

半世苍凉 提交于 2019-12-03 05:17:50
问题 I'm trying to understand how I will be able to craft an API using ASP.NET Web API which will be protected from CSRF, while still being accessible from non-web environments (e.g. native mobile applications). My first thought would be that a non-web environment can never successfully pass an anti-forgery token validation, since it doesn't have a form that is posted. Is this true? Is there any way to make validation work? If there isn't a way to validate, my second thought is to offer an API

Enable Antiforgery Token with ASP.NET Core and JQuery

房东的猫 提交于 2019-12-03 01:58:11
I am using JQuery with ASP.NET Core 1.0.1 and I have the Ajax call: $("#send-message").on("submit", function (event) { event.preventDefault(); var $form = $(this); $.ajax({ url: "api/messages", data: JSON.stringify($form.serializeToJSON()), dataType: "json", headers: { Accept: "application/json", "Content-Type": "application/json" }, type: "post" }) .done(function (data, status, xhr) { }) .fail(function (xhr, status, error) { }); To the ASP.NET Core action: [HttpPost("messages")] public async Task<IActionResult> Post([FromBody]MessagePostApiModelModel model) { // Send message } The form is in

AntiForgeryToken deprecated in ASP.Net MVC 4 RC

放肆的年华 提交于 2019-12-03 01:11:11
I just installed ASP.Net MVC 4 RC to replace ASP.Net MVC 4 beta. When trying to run an existing application I'm getting an error message that AntiForgeryToken has been deprecated. Here's my code: using (Html.BeginForm("", "", FormMethod.Post, new { id = "MonthElectionForm" })) { @Html.AntiForgeryToken("AddEditMonthElection") } ---- UPDATE --- ASP.Net MVC 4 RC has made the Salt property obsolete for ValidateAntiForgeryToken attribute and AntiForgeryToken html helper. So, now my code looks like this: controller: [HttpPost] [ValidateAntiForgeryToken] public JsonResult CreateCompany

The required anti-forgery cookie “__RequestVerificationToken” is not present

僤鯓⒐⒋嵵緔 提交于 2019-12-02 20:22:27
My website is raising this exception around 20 times a day, usually the form works fine but there are instances where this issue occur and I don't know why is so random. This is logged exception by elmah 500 HttpAntiForgery The required anti-forgery cookie __RequestVerificationToken" is not present. But the form it is sending the the token as shown on the XML log by elmah <form> <item name="__RequestVerificationToken"> <value string="DNbDMrzHmy37GPS6IFH-EmcIh4fJ2laezIrIEev5f4vOhsY9T7SkH9-1b7GPjm92CTFtb4dGqSe2SSYrlWSNEQG1MUlNyiLP1wtYli8bIh41"/> </item> <item name="toPhone"> <value string=

How does ValidateAntiForgeryToken fit with Web APIs that can be accessed via web or native app?

心不动则不痛 提交于 2019-12-02 18:34:36
I'm trying to understand how I will be able to craft an API using ASP.NET Web API which will be protected from CSRF , while still being accessible from non-web environments (e.g. native mobile applications). My first thought would be that a non-web environment can never successfully pass an anti-forgery token validation, since it doesn't have a form that is posted. Is this true? Is there any way to make validation work? If there isn't a way to validate, my second thought is to offer an API which validates anti-forgery tokens for web calls but not for non-web calls. However, it seems like an

Secure way to stop users from forging forms

时间秒杀一切 提交于 2019-12-02 07:28:35
How can I prevent users from forging forms on the PHP or jquery side, I am using Jquery's ajax functionality to submit the forms, and this means that tech-wise people can change some variables such as the value of something (that shouldn't be changed / is a user id or something like that) through the use of firebug or web inspector and likewise. So how can I prevent users from changing these variables or making sure they are unchangeable through a secure and good way? Thanks Albireo As the others have already stated, you can't prevent the user from tampering. You are receiving data from me,

Why AntiForgeryToken validation keeps failing?

自作多情 提交于 2019-12-02 03:50:58
问题 I am developing a web API app running using asp.net core2 and Angular . The detailed development environment config is here. I am trying to configure AntiForgeryToken validation but it keeps failing. I followed the config. here, but I had to modify it as my angular app and asp.net servers are running on two different ports because the front end startup doesn't generate the token. I kick start the backend by calling an API path ( /api/Account/ContactInitialization ) at the app component

MVC AntiForgeryToken machinekey for encryption

拟墨画扇 提交于 2019-12-01 19:27:30
i came to know : Under the covers, the MVC AntiForgeryToken attribute uses the machinekey for encryption. If you don't specify a machinekey in the web.config , one is automatically generated for you by ASP.NET. If the ASP.NET application is restarted (e.g. do an iisreset), the AntiForgeryToken within the browser cookie will still be encrypted with an old machine key, hence why it crashes with the above error. My concern is before write the machine key in web.config i like to know where i should look for the machine key to copy & paste in web.config. when we are testing in local pc then we can

HOWTO do CSRF protection in Struts2 application for AJAX requests

时间秒杀一切 提交于 2019-12-01 11:14:57
I have a struts2 webapp in which I need to implement CSRF protection. For statis forms it is pretty straight forward. I just need to activate the tokenSession interceptor & then set <s:token/> in the form to be submitted. (explained here and here ) But the problem appears when I need to enable CSRF protection for POST AJAX calls (I am using jQuery) which are not necessarily submitted via forms. I face the issue of re-using token when making subsequent AJAX calls. Any pointers or different approaches are appreciated. Currently I have resolved the issue by generating tokens for AJAX requests and

HOWTO do CSRF protection in Struts2 application for AJAX requests

这一生的挚爱 提交于 2019-12-01 08:51:01
问题 I have a struts2 webapp in which I need to implement CSRF protection. For statis forms it is pretty straight forward. I just need to activate the tokenSession interceptor & then set <s:token/> in the form to be submitted. (explained here and here) But the problem appears when I need to enable CSRF protection for POST AJAX calls (I am using jQuery) which are not necessarily submitted via forms. I face the issue of re-using token when making subsequent AJAX calls. Any pointers or different