gpt4 book ai didi

security - JsonWebToken : activity-based expiration vs issuing time-based expiration

转载 作者:行者123 更新时间:2023-12-01 23:44:49 27 4
gpt4 key购买 nike

我对基于 token 的授权相当陌生。我正在尝试找出自定义过期/ token 刷新方案中的缺陷。

我在 Express API 中有一个基本的 JWT 身份验证设置;我将 JWT 过期时间设置为 1 小时;但是,JWT 检查相对于 token 颁发时间的 token 过期时间。我希望每次成功的 api 调用后都会重置过期时间。如果我的用户活跃使用该应用程序超过一个小时,我不希望他们必须重新登录才能刷新 token (并且可能会丢失他们正在处理的任何数据。)

另一方面,如果它们超过一个小时没有响应,我确实希望 token 过期。

我想出了以下方法:

During every successful API request, issue a new JWT and send it in a custom response header. My client side code is responsible for checking this JWT response header and using its value as the new default Authorization request header. Thus, if there is no API request from the user for more than 1 hour, the token will expire and not be refreshed. Login would then be required. In addition, the original issue-date of the token (timestamp of login-authentication) will be stored so that a "hard-expiration" of the token will be enforced after 24 hours.

这看起来相当简单且相当安全,但我在 JWT 研究中没有看到任何对此的引用。有没有更好的方法来实现同样的目标?我是否错过了这种方法的主要安全漏洞?

更新:经过一段时间的思考,我意识到这样做的问题在于,它为重放攻击打开了大门,而 token 过期是无法阻止的。因此绝对应该进行“硬过期”检查:无论最近的用户事件如何,硬过期都会使 token 在发行日期后的某个时间失效。

最佳答案

在这里您可以查看我对这种情况的回答: implementing refresh-tokens with angular and express-jwt

我所做的是有一个时间窗口,服务器检查 token 过期和本地服务器时间是否在此窗口内,然后发送带有刷新 token 的响应 header 。

关于security - JsonWebToken : activity-based expiration vs issuing time-based expiration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27408762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com