gpt4 book ai didi

security - 在多个设备上使用 token 和系列实现记住我

转载 作者:行者123 更新时间:2023-12-03 22:21:31 25 4
gpt4 key购买 nike

我正在尝试使用此处概述的系统实现“记住我”实用程序:Improved persistent login cookie

但是,这里的逻辑对我来说存在问题,想知道是否有人可以为我解决这个问题。

  • 为用户提供了一个 session ID。这是一个随机生成的字符串,是
    在用户帐户的整个生命周期内保持不变。
  • 给用户一个 token ID。这是一个随机生成的字符串和
    每次用户成功登录时都会重新创建。

  • 这两个值都作为签名 cookie 存储在用户的机器和数据库中。

    这个想法是,如果有人设法欺骗用户的 token 和系列并以用户身份登录,那么他们将生成一个新的 token ID。下次合法用户尝试登录时,他们将有一个匹配的系列但无效的 token ,从而通知系统发生了安全漏洞并且可以采取任何必要的操作(清除用户的 token )。

    这很棒。但是,当用户尝试从多个设备或浏览器使用我的应用程序时会发生什么?假设用户使用 Chrome 登录我的服务并检查记住我。下次他们通过 Firefox 登录并选择记住我时。将生成一个新 token ,以便用户下次尝试使用 Chrome 登录时会触发虚假盗窃 - 不是吗?

    如果是这种情况,我该如何更可靠地实现此解决方案?我很清楚基于 cookie 的授权本质上不太安全,并且不允许 cookie 授权用户执行任何破坏性操作,例如购买。

    最佳答案

    “改进的持久登录 cookie”所指的原始帖子(在此处找到: http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/ )指出:

    The cookie should consist of the user's username, followed by a separator character, followed by some large random number (128 bits seems mind-bogglingly large enough to be acceptable). The server keeps a table of number->username associations, which is looked up to verify the validity of the cookie. If the cookie supplies a random number and username that are mapped to each other in the table, the login is accepted.

    At any time, a username may be mapped to several such numbers



    因此,用户可以同时拥有多个持久 token 。

    关于security - 在多个设备上使用 token 和系列实现记住我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944073/

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