gpt4 book ai didi

security - 服务器端检查cookie是否被盗

转载 作者:行者123 更新时间:2023-12-05 01:08:22 24 4
gpt4 key购买 nike

有没有办法在服务器端检查用户 A 的 cookie 是否被用户 B 窃取?

例如使用简单的哈希函数创建的 cookie token /数据(例如 sha1)

hash_of(user_agent,ip+proxy_ip,username,random_session_key)

where user_agent is browser's user agent,
ip is the client IP address,
proxy_ip is the proxy's IP address the client use,
username is the username the user currently login,
random_session_key is a random number saved to database when a user logged in

如果该 cookie 被 LAN 上的其他人窃取并使用,并且 LAN 使用的不是任何代理而是 NAT,并且小偷使用的是完全相同的浏览器(或欺骗用户代理),那么我们在服务器端如何检测那?

最佳答案

是的,有办法。它被称为 Secure Cookie Protocol .

您正在使用 SSL 吗? (因为如果你不是,整个谈话都是毫无意义的)。

好吧,您对 cookie 进行了加密,但使用的是 SSL session 标识符。假设 SSL 为您提供足够的端点安全性(强密码等),SCP 应该保护您的数据并允许您判断另一个 SSL session 何时尝试使用相同的 cookie(因为 sessionid 会发生变化,因此 MAC 会发生变化)。

key = HMAC(user name|expiration time, secret_key)
cookie = user name|expiration time|encrypt(data, key)
cookie = cookie | HMAC( user name|expiration time|data|sessionid, key)

所以基本上,您是根据 SSL session 标识符创建唯一的验证码。

请注意,REMOTE_ADDR 或用户代理从不考虑。除非您物理上破坏了客户端框,否则它使用的唯一因素是非常不容易欺骗的东西......

关于security - 服务器端检查cookie是否被盗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17232361/

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