ruby-on-rails - 从 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
我可以看到正确的值。
解决方案
推荐阅读
- r - 如何计算所有重复中每种处理的平均值
- c# - 无法访问已关闭的流 && HTMLWorker 已过时
- php - PayPal PHP SDK 不适用于订阅,获取 RESOURCE_NOT_FOUND
- c# - 在循环中将 @ref 添加到 Blazor 组件
- javascript - How to add multiple routes using mapquest api, L.mapquest.directions().route()?
- android - java.lang.IllegalStateException: sensorManager.getDefaultSensor(sensorType) 在 Flutter 中不能为 null
- python - 如何在scrapy中按项目将下载的文件分组在同一子目录中?
- algorithm - 用预言机有效地对整数进行素数分解
- java - 打开程序时在 Java 中获取用户输入
- javascript - 检查光标何时悬停在链接上(尤其是 YouTube 链接)