如何使 CouchDB 中的用户令牌无效?

How to invalidate a users token in CouchDB?

官方文档说明了以下关于删除用户 cookie 的内容: Link

DELETE /_session

Closes user’s session by instructing the browser to clear the cookie. This does not invalidate the session from the server’s perspective, as there is no way to do this because CouchDB cookies are stateless. This means calling this endpoint is purely optional from a client perspective, and it does not protect against theft of a session cookie.

我可以使客户端上的 cookie 无效,但如果有人窃取 AuthSession=123abc 并悄悄使用它怎么办?这不是安全问题吗?

我想知道如何避免这种行为并真正销毁 cookie,因为我想要一个安全的 CouchDB 应用程序。

我确定我以前回答过这个问题,但我找不到重复的问题,所以这里再说一遍:

cookie 是用户登录名、cookie 创建时间、用户密码盐和服务器机密的简单哈希值。

这意味着要使现有的 cookie 无效,您必须等待足够的时间过去以确保创建的时间戳在过去足够远以至于 cookie 被视为无效,或者更改 cookie 的其他部分之一散列。

实际上,这通常意味着这是不可能的,因为:

  1. 更改用户名意味着用户将无法再登录。
  2. 更改用户的密码 salt 也意味着用户无法再登录,除非您还存储了用户的明文密码,以便可以重新计算他​​们的密码哈希值。 (可能是一个非常糟糕的主意)
  3. 更改服务器机密将使所有 会话对所有 用户无效,而不仅仅是您的目标用户。

如果使活动会话无效是您应用程序的硬性要求,最好在处理身份验证并使用 proxy authentication 与 CouchDB 交互的反向代理服务器中完成。