简体   繁体   English

如何安全处理Rest API用户身份验证?

[英]How to handle Rest API user authentication securely?

For the last few months i've been working on a Rest API for a web app for the company I work for. 在过去的几个月中,我一直在为我工作的公司开发Web应用程序的Rest API。 The endpoints supply data such as transaction history, user data, and data for support tickets. 端点提供数据,例如交易历史记录,用户数据和支持凭单数据。 However, I keep running into one issue that always seems to set me back to some extent. 但是,我一直遇到一个似乎总是使我退缩的问题。

The issue I seem to keep running into is how do I handle user authentication for the Rest API securely? 我似乎一直遇到的问题是如何安全处理Rest API的用户身份验证? All data is going to be sent over a SSL connection, but there's a part of me that's paranoid about potential security problems that could arise. 所有数据都将通过SSL连接发送,但是我当中有一部分人对可能出现的潜在安全问题抱有幻想。 As it currently stands when a client attempts to login the client must provide a username or email address, and a password to a login endpoint (EG "/api/login"). 目前,当客户端尝试登录时,客户端必须提供用户名或电子邮件地址,以及登录端点的密码(例如,“ / api / login”)。 Along with with this information, a browser fingerprint must be supplied through header of the request that's sending the login credentials. 连同此信息一起,必须通过发送登录凭据的请求的标头提供浏览器指纹。 The API then validates whether or not the specified user exists, checks whether or not the password supplied is correct, and stores the fingerprint in a database model. 然后,API验证指定的用户是否存在,检查提供的密码是否正确,并将指纹存储在数据库模型中。 To access any other endpoints in the API a valid token from logging in, and a valid browser fingerprint are required. 要访问API中的任何其他终结点,必须先登录才能获得有效的令牌以及有效的浏览器指纹。

I've been using browser fingerprints as a means to prevent token-hijacking, and as a way make sure that the same device used to login is being used to make the requests. 我一直在使用浏览器指纹来防止令牌劫持,并确保使用用于登录的同一设备来发出请求。 However, I have noticed a scenario where this practice backfires on me. 但是,我注意到这种情况适得其反。 The client-side library i'm using to generate browser fingerprints isn't always accurate. 我用来生成浏览器指纹的客户端库并不总是准确的。 Sometimes the library spits out a different fingerprint entirely. 有时,库会完全吐出另一个指纹。 Which causes some client requests to fail as the different fingerprint isn't recognized by the API as being valid. 由于不同的指纹未被API识别为有效指纹,因此这导致某些客户端请求失败。 I would like to keep track of what devices are used to make requests to the API. 我想跟踪使用什么设备向API发出请求。 Is there a more consistent way of doing so, while still protecting tokens from being hijacked? 在保护令牌免遭劫持的同时,是否有更一致的方法?

When thinking of the previous question, there is another one that also comes to mind. 当想到上一个问题时,还会想到另一个问题。 How do I store auth tokens on client-side securely, or in a way that makes it difficult for someone to obtain the tokens through malicious means such as a xss-attack? 如何将身份验证令牌安全地存储在客户端上,或者以某种方式使某人难以通过诸如xss-attack之类的恶意手段来获取令牌? I understand setting a strict Content-Security Policy on browser based clients can be effective in defending against xss-attacks. 我知道在基于浏览器的客户端上设置严格的内容安全策略可以有效地防御xss攻击。 However, I still get paranoid about storing tokens as cookies or in local storage. 但是,我仍然对将令牌存储为cookie或本地存储感到疑惑。

I understand oauth2 is usually a good solution to user authentication, and I have considered using it before to deal with this problem. 我知道oauth2通常是用户身份验证的一个很好的解决方案,并且我已经考虑过使用它来处理此问题。 Although, i'm writing the API using Flask, and i'm also using JSON Web tokens. 虽然,我正在使用Flask编写API,并且还在使用JSON Web令牌。 As it currently stands, Flask's implementation of oauth2 has no way to use JWTs as access tokens when using oauth for authentication. 就目前而言,在使用oauth进行身份验证时,Flask的oauth2实现无法使用JWT作为访问令牌。

This is my first large-scale project where I have had to deal with this issue and i am not sure what to do. 这是我不得不处理此问题的第一个大型项目,我不确定该怎么做。 Any help, advice, or critiques are appreciated. 任何帮助,建议或批评都将受到赞赏。 I'm in need of the help right now. 我现在需要帮助。

Put an API Gateway in front of your API , your API Gateway is publicly ( ie in the DMZ ) exposed while the actual API are internal. 将API网关放在您的API之前,您的API网关是公开的(即在DMZ中),而实际的API是内部的。

You can look into Kong.. 你可以看看孔..

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

相关问题 领英 REST API 认证 - LinkedIn REST API Authentication JWT 使用 Django REST 框架进行身份验证,使用 otp 获取 Z8A5DA52ED1264471D35AZE70C08A - JWT Authentication with Django REST Framework using otp for getting api tokens Django Rest API Url 图案处理。 (点)符号 - Django Rest API Url Pattern to handle . (dot) symbol 我如何在我的 web 应用程序上安全地接受和运行用户代码? - How can i accept and run user's code securely on my web app? 我如何安全地防止用户在我的脚本中获取字符串? - How would I securely prevent a user from getting a string in my script? 如何安全地将 API 凭据传递到托管我的 python 脚本的远程 Heroku 服务器? - How do I securely pass API credentials to a remote Heroku server that my python script is hosted on? Django REST 框架 API:如何在 ZEF6784A1DA0D4D7 服务器上使用用户提供的名称(例如 username.jpg)保存/上传图像 - Django REST Framework API : How to save/upload images with the name given by user(e.g. username.jpg) at Django server REST:Glassdoor API在标头中需要User-Agent - REST: Glassdoor API requires User-Agent in header 如何处理 Django 中的多种动态用户类型? - How to handle multiple dynamic user types in Django? Django rest框架认证 - Django rest framework authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM