在两个 Rails 个不同版本的应用程序之间共享 Devise 会话 cookie

Share Devise session cookie between two Rails apps of different versions

我正在尝试在同一 TLD 但位于不同子域上的两个 Rails 应用程序之间共享 Devise 会话 cookie 以进行身份​​验证。一个应用程序是 v4.2.11.1,另一个是 v6.0.3.2。我想登录 Rails 4 应用程序,并在 Rails 6 应用程序中访问经过身份验证的用户信息。登录 Rails 4 应用程序时,会话 cookie 设置正常,但在 Rails 6 应用程序中尝试访问它时,它似乎被完全擦除 out/reset。

在您的特定情况下可能还有其他事情发生,但是自 Rails 4 以来会话 cookie 有两次 backward-incompatible 更改是毫无价值的,您需要查看这些更改在

  1. Rails5.2 中发生了变化,将过期信息嵌入到加密的 cookie 中。来自 upgrade guide:

To improve security, Rails now embeds the expiry information also in encrypted or signed cookies value.

This new embed information make those cookies incompatible with versions of Rails older than 5.2.

If you require your cookies to be read by 5.1 and older, or you are still validating your 5.2 deploy and want to allow you to rollback set Rails.application.config.action_dispatch.use_authenticated_cookie_encryption to false.

  1. Rails 6.0 更改为在加密 cookie 中嵌入用途。从 升级 指南:

To improve security, Rails embeds the purpose information in encrypted or signed cookies value. Rails can then thwart attacks that attempt to copy the signed/encrypted value of a cookie and use it as the value of another cookie.

This new embed information make those cookies incompatible with versions of Rails older than 6.0.

If you require your cookies to be read by Rails 5.2 and older, or you are still validating your 6.0 deploy and want to be able to rollback set Rails.application.config.action_dispatch.use_cookies_with_metadata to false.