Skip to content

A platform for community discussion. Free, open, simple.

DEV: Serialize cookies using MessagePack (#35082)

Loïc Guitauta9c988a606f7
diff --git a/config/application.rb b/config/application.rb
index c79a01139f5..6724d376ab4 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -89,7 +89,7 @@ module Discourse
Symbol,
]
config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1
- config.action_dispatch.cookies_serializer = :hybrid
+ config.action_dispatch.cookies_serializer = :message_pack_allow_marshal
config.action_controller.wrap_parameters_by_default = false
config.active_support.cache_format_version = 7.1
diff --git a/lib/freedom_patches/message_pack_extensions.rb b/lib/freedom_patches/message_pack_extensions.rb
new file mode 100644
index 00000000000..227c5d92384
--- /dev/null
+++ b/lib/freedom_patches/message_pack_extensions.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+# Patch from https://github.com/rails/rails/pull/54584.
+# TODO: Drop this once Rails 8.1 is released.
+
+require "active_support/message_pack"
+require "active_support/core_ext/string/output_safety"
+
+module MessagePackExtensions
+ def install(registry)
+ super
+ registry.register_type 18, ActiveSupport::SafeBuffer, packer: :to_s, unpacker: :new
+ end
+end
+
+ActiveSupport::MessagePack::Extensions.prepend(MessagePackExtensions)