首页 > 解决方案 > 从 Rails 4.2 升级到 Rails 5.2:Cookie 数据不再可读

问题描述

我正在将 Rails 4.2 应用程序迁移到 Rails 5.2。

在代码中,我们设置了一个 cookie:

cookies.permanent.signed["wsid#{session[:user_id]}".to_sym] = { value: wsid, httponly: true }

然后将其取回:

cookies.permanent.signed["wsid#{session[:user_id]}".to_sym]

升级 Rails 后,该值不再可读。

在仔细检查了升级 Ruby on Rails 指南后,我发现从 Rails 5.1 迁移到 5.2,cookie 发生了变化

所以我在所有环境文件中添加了以下内容:

  # controls whether signed and encrypted cookies use the AES-256-GCM cipher or
  # the older AES-256-CBC cipher. It defaults to true.
  config.action_dispatch.use_authenticated_cookie_encryption = false

但我仍然无法访问这些值。

有人可以帮我吗?

更新

我读到了secret_key_base,我知道这cookies是在对数据进行加密,但实际上上面代码定义的值似乎没有被加密,因为使用Base64.decode64我可以看到正确的值。

标签: ruby-on-railscookies

解决方案


推荐阅读