将过期令牌放入黑名单 table 是个好主意吗?
is it a good idea to put expired tokens to blacklist table?
首先,这是我当前的身份验证流程的样子
- 用户登录
- 用户得到一个 refresh_token 分配并存储在数据库中(长期存在 7 天)
- 客户端收到一个accestoken(短暂,2h),并将其存储为cookie。 Client 也收到 AES 加密后的 userId,并存储
它作为一个 cookie。
- 只要访问令牌没有过期,用户就会继续使用令牌浏览网站
- 令牌过期
- 过期的访问令牌被发送到刷新端点,当前存储在 cookie 中的用户 ID(Aes 加密)也是如此。
- 服务器解密userId,使用out userId从数据库中选择refresh token,获取用户对应的refreshtoken。
- 现在我们在服务器中有了我们的刷新令牌和访问令牌,所以我们刷新令牌,并发回新的访问令牌。我们还生成一个新的刷新令牌,并用新的刷新令牌覆盖数据库中的旧刷新令牌。
我的问题基本上与最后一步有关。由于这些刷新令牌在技术上仍然有效,因为它们的到期时间很长。我可以在名为 "blacklisted_tokens" 的数据库中创建一个 table 或类似的东西,并将令牌的值存储在那里吗?然后在生成新的访问令牌之前,它应该先检查该刷新令牌是否在该数据库中,这意味着它将被列入黑名单。
这是授权流程图
My question is basically related to that last step. Since those
refresh tokens are still technically valid, since they have a long
expiration time. Can I create a table in my database named
"blacklisted_tokens" or something like that, and store there the
values of the token? And then right before generating a new access
token it should prior to that check if that refresh token is or isnt
in that database, meaning that it will be blacklisted.
不建议这样做,因为生成 2 个相同令牌的概率很低,并且向您的后端添加 NOT 必要的额外进程不是一个好主意并且大规模令牌重新生成的性能问题(很多用户)。
此外,令牌与身份 (id) 一起降低了安全风险。
如果我是你,我会把新令牌重写成旧令牌。
威胁代币的最重要的网络攻击类型是 Sniffing attack,通过执行以下步骤,实际上这种攻击的可能性几乎为零:
- SSL 证书
- 令牌过期并重新生成
- 咸请求
盐
In cryptography, a salt is random data that is used as an additional
input to a one-way function that hashes data, a password or
passphrase. Salts are used to safeguard passwords in storage.
首先,这是我当前的身份验证流程的样子
- 用户登录
- 用户得到一个 refresh_token 分配并存储在数据库中(长期存在 7 天)
- 客户端收到一个accestoken(短暂,2h),并将其存储为cookie。 Client 也收到 AES 加密后的 userId,并存储 它作为一个 cookie。
- 只要访问令牌没有过期,用户就会继续使用令牌浏览网站
- 令牌过期
- 过期的访问令牌被发送到刷新端点,当前存储在 cookie 中的用户 ID(Aes 加密)也是如此。
- 服务器解密userId,使用out userId从数据库中选择refresh token,获取用户对应的refreshtoken。
- 现在我们在服务器中有了我们的刷新令牌和访问令牌,所以我们刷新令牌,并发回新的访问令牌。我们还生成一个新的刷新令牌,并用新的刷新令牌覆盖数据库中的旧刷新令牌。
我的问题基本上与最后一步有关。由于这些刷新令牌在技术上仍然有效,因为它们的到期时间很长。我可以在名为 "blacklisted_tokens" 的数据库中创建一个 table 或类似的东西,并将令牌的值存储在那里吗?然后在生成新的访问令牌之前,它应该先检查该刷新令牌是否在该数据库中,这意味着它将被列入黑名单。
这是授权流程图
My question is basically related to that last step. Since those refresh tokens are still technically valid, since they have a long expiration time. Can I create a table in my database named "blacklisted_tokens" or something like that, and store there the values of the token? And then right before generating a new access token it should prior to that check if that refresh token is or isnt in that database, meaning that it will be blacklisted.
不建议这样做,因为生成 2 个相同令牌的概率很低,并且向您的后端添加 NOT 必要的额外进程不是一个好主意并且大规模令牌重新生成的性能问题(很多用户)。
此外,令牌与身份 (id) 一起降低了安全风险。
如果我是你,我会把新令牌重写成旧令牌。
威胁代币的最重要的网络攻击类型是 Sniffing attack,通过执行以下步骤,实际上这种攻击的可能性几乎为零:
- SSL 证书
- 令牌过期并重新生成
- 咸请求
盐
In cryptography, a salt is random data that is used as an additional input to a one-way function that hashes data, a password or passphrase. Salts are used to safeguard passwords in storage.