插件中ActiveSupport::MessageEncryptor::InvalidMessage出现问题

2.9.0.beta5 的更新导致我的仪表板插件出现问题。在插件的一个视图中触发了错误:

Started GET "/pfaffmanager/servers" for 73.147.117.173 at 2022-06-14 17:53:31 +0000
Processing by Pfaffmanager::ServersController#index as HTML
  Rendered default/empty.html.erb within layouts/application (Duration: 0.1ms | Allocations: 29)
  Rendered layout layouts/application.html.erb (Duration: 21.6ms | Allocations: 7109)
Completed 200 OK in 142ms (Views: 23.0ms | ActiveRecord: 0.0ms | Allocations: 37464)
Started GET "/chat/chat_channels.json" for 73.147.117.173 at 2022-06-14 17:53:31 +0000
Processing by DiscourseChat::ChatChannelsController#index as JSON
Started GET "/presence/get?channels%5B%5D=%2Fchat-user%2Fchat%2F1&channels%5B%5D=%2Fchat-user%2Fcore%2F1" for 73.147.117.173 at 2022-06-14 17:53:31 +0000
Processing by PresenceController#get as JSON
  Parameters: {"channels"=>["/chat-user/chat/1", "/chat-user/core/1"]}
Completed 200 OK in 44ms (Views: 1.9ms | ActiveRecord: 0.0ms | Allocations: 5134)
Started GET "/pfaffmanager/servers" for 73.147.117.173 at 2022-06-14 17:53:31 +0000
Completed 200 OK in 94ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 22124)
Processing by Pfaffmanager::ServersController#index as JSON
Completed 500 Internal Server Error in 113ms (ActiveRecord: 0.0ms | Allocations: 15487)
ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
(eval):9:in `_fast_attributes'
app/controllers/application_controller.rb:543:in `render_json_dump'
app/controllers/application_controller.rb:415:in `block in with_resolved_locale'
app/controllers/application_controller.rb:415:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:368:in `call'
config/initializers/008-rack-cors.rb:25:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:202:in `call'

这似乎只发生在我的插件的索引视图中,而不是插件中的其他页面或 Discourse 中。我不知道该去哪里找。很高兴我先在我的暂存站点上运行了升级!

上面的内容提示我这与聊天插件有关,但它发生在我的开发实例上,而没有安装聊天。

哇,在谷歌上搜索 ActiveSupport::MessageEncryptor::InvalidMessage "fast_attributes" 只返回了这个主题!

1 个赞

我的问题似乎与 config/master.key 有关(https://stackoverflow.com/questions/54277392/rails-activesupportmessageencryptorinvalidmessage),但不明白为什么会在这次升级中开始出现。

1 个赞

我们已更新至 Rails 7,这可能是原因所在。

1 个赞

谢谢,@gerhard

Upgrading Ruby on Rails — Ruby on Rails Guides

我发现

(但这说的是 Rails 7.1?)

您是否知道有什么方法可以在我的现有插件中通过在 plugin.rb 中添加一行显而易见(一旦你知道它)的代码来忽略此更改?

或者我可能需要弄清楚这是什么意思。

编辑:但在 dev 中将该行添加到 config/application.rb 并不是一个神奇的修复。

抱歉。我继续往下读了:

所以也许这能解决我目前的问题。再次感谢您的帮助!也许这次我能明白了。


嗯,我为 rails 6 和 rails 7 生成的密钥看起来像这样:

#<ActiveSupport::KeyGenerator:0x000055870212d4f8 @hash_digest_class=OpenSSL::Digest::SHA1, @iterations=65536, @secret="my-big-secret">

但它们加密的方式不同。我希望 hash_digest_class 是问题所在,但它至少在两者上看起来都一样,但加密后的字符串却不同。:crying_cat_face:

1 个赞

哦。糟糕。不,不是那个原因。我正在运行的生产站点是 7.0.3 版本,而损坏的暂存站点也是 7.0.3 版本。它加密的方式不同。我无法确定,也不知道如何确定,是序列化器不同还是密码不同。

与此同时,我了解到 7.0 支持加密字段,如果我能弄清楚如何访问我的加密 API 密钥,这将使我能够移除一些自定义代码。或者我可能只是删除并重新生成它们。

截至最新,我得到的加密是
=> "SUNBZlRURThEZjdVUG8wTzV1eWk0dz09LS1uRGVSQWtPRU9rc1ZCa1Y1d2pyeU5nPT0=--43eab316e6a9ebafc72d4982347abd9c7f6605db"

使用 2.9.0.beta4 版本,它们看起来像 "FwL/GGvrDHOpQ1bnGiI=--kCLbUxMf/XeMaeWF--/feRN+/l1q3EFdKgyIo+7Q=="

我需要在这里添加旧的密码:

k = ActiveSupport::MessageEncryptor.new(KEY,  cipher: "aes-256-cbc")

我仍然不明白为什么两个声称运行 7.0.3 的实例会产生不同的结果,但仔细阅读升级文档非常有帮助。谢谢你,Gerhard!这正是我需要的推动。

1 个赞