简体   繁体   English

用于移动设备的REST Web API-CSRF保护?

[英]REST web API for mobile devices - CSRF protection?

I know about CSRF attacks and protection against them inside and out, I've read the entire owasp page regarding it, but I'm a bit at a loss when it comes to protecting REST APIs. 我了解CSRF攻击并从内到外对其进行保护,我已经阅读了有关它的整个owasp页面,但是在保护REST API方面我有点茫然。

I'm developing a RESTful web API for a mobile application. 我正在为移动应用程序开发RESTful Web API。 To authenticate users, I'm using an oauth server package (password flow grant) and my custom-built social grant for the facebook's manual login flow (we have both local and facebook accounts in our database). 为了对用户进行身份验证,我使用了oauth服务器软件包(密码流授予)和针对Facebook的手动登录流程(我们的数据库中同时包含本地帐户和Facebook帐户)的定制社交权限。 Both of these grants generate our application-specific access tokens that the client (mobile app) sends to the server with each request (in the Authorization header) to reassure that he/she is a logged in user. 这两个授予都会生成我们的特定于应用程序的访问令牌,客户端(移动应用程序)会随每个请求(在Authorization标头中)将其发送到服务器,以确保他/她是已登录的用户。

Doesn't this alone mitigate the CSRF attack window? 这本身不能减轻CSRF攻击窗口吗? If not, what should I do to protect my server against these attacks? 如果没有,我该怎么做才能保护服务器免受这些攻击?

PS I suppose checking the referrer header is not going to help here, because the referrer would differ from my server's domain, right? PS:我想检查引荐来源标头在这里无济于事,因为引荐来源方与我服务器的域不同,对吗?

Ok first thing, CSRF attack requires one important application called browser . 好的,首先,CSRF攻击需要一个名为browser重要应用程序。 No one can simply trick your mobile application to send a request along with credentials to api server. 没有人可以简单地欺骗您的移动应用程序将请求和凭据发送到api服务器。 So your mobile applications is particularly safe from CSRF attacks. 因此,您的移动应用程序特别容易受到CSRF攻击。

However, the problem arises if you use same api server for communications with web frontend(If your application has a corresponding web application too). 但是,如果您使用相同的api服务器与Web前端进行通信(如果您的应用程序也具有相应的Web应用程序),则会出现问题。 In that case, you'd have to separate the API server for mobile application and web frontend, with CSRF prevention ACTIVE for web frontend API calls. 在这种情况下,您必须将用于移动应用程序和Web前端的API服务器分开,并针对Web前端API调用使用CSRF预防ACTIVE OR, you can use the same API server, if you can somehow differentiate the call from web & mobile. 或者,如果可以通过某种方式将呼叫与网络和移动设备区分开,则可以使用同一API服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM