使用 REST API 进行适当的会话管理 [英] Proper Session Management with REST API

查看:115
本文介绍了使用 REST API 进行适当的会话管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了 RESTful API 的设计,其中我使用作为参数发送的 API 令牌对每个请求进行身份验证.
现在我想创建一个客户端界面,我想知道管理与每个浏览器客户端的会话的正确安全方法是什么.

I've finished designing a RESTful API, in which I authenticate each request with an API Token that's sent as a param.
Now I want to create a client interface, and I was wondering what's a properly secure way to manage a session with each browser client.

我想过一个流程来保持服务器端无状态:

I've thought about a flow to keep the server side stateless:

  • Web 客户端使用用户名和密码登录
  • 服务器响应用户的 API 令牌
  • 客户端将令牌存储为 cookie
  • 客户端将令牌作为参数与每个请求一起发送,正如 API 服务器所期望的

但我觉得这里有些不对劲……这不是太脆弱了吗?
让我们假设我正在使用 SSL,但仍然,
这样 API 令牌不会很容易被盗吗?
它甚至是一种正确的工作方式吗?

But something doesn't seem right to me here... isn't this too vulnerable?
Let's assume I'm using SSL, but still,
can't the API token be stolen easily that way?
Is it even a proper way to work?

推荐答案

将您的令牌存储在网络应用程序的 cookie 中,因为它们提供了额外的安全性,以及保护的简单性使用现代 Web 框架对抗 CSRF.HTML5 网络存储是容易受到 XSS 攻击,具有更大的攻击面,并且可以影响成功攻击的所有应用程序用户.

Store your tokens in cookies for web applications, because of the additional security they provide, and the simplicity of protecting against CSRF with modern web frameworks. HTML5 Web Storage is vulnerable to XSS, has a larger attack surface area, and can impact all application users on a successful attack.

参考以下链接:

https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage

这篇关于使用 REST API 进行适当的会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆