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

前端 未结 3 1190
傲寒
傲寒 2021-02-01 10:01

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

3条回答
  •  灰色年华
    2021-02-01 10:43

    Take a look at the CORS implementation for WebAPI.

    http://blogs.msdn.com/b/carlosfigueira/archive/2012/07/02/cors-support-in-asp-net-web-api-rc-version.aspx

    Then you could allow only localhost as a valid URI on the webapi server. This would prevent other sites from loading attack code in the browser.

提交回复
热议问题