From 4d04f9beee186be7e07ed9d2de935555e35ee092 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Tue, 2 Dec 2025 11:34:12 +0100 Subject: [PATCH] Use urlsafe base64 decode --- lib/rails_ext/action_text_attachables.rb | 2 +- test/lib/rails_ext/action_text_attachables_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rails_ext/action_text_attachables.rb b/lib/rails_ext/action_text_attachables.rb index e602346..e0d41f5 100644 --- a/lib/rails_ext/action_text_attachables.rb +++ b/lib/rails_ext/action_text_attachables.rb @@ -20,7 +20,7 @@ ActiveSupport.on_load(:action_text_content) do # Rails 7 used an older format of GID that serialized the payload using Marshall # Since we intentionally skip signature verification, we can't safely unmarshal the data # To work around this, we manually extract the GID from the marshaled data - Base64.strict_decode64(data).match(%r{(gid://campfire/[^/]+/\d+)})&.to_s + Base64.urlsafe_decode64(data).match(%r{(gid://campfire/[^/]+/\d+)})&.to_s else nil end diff --git a/test/lib/rails_ext/action_text_attachables_test.rb b/test/lib/rails_ext/action_text_attachables_test.rb index d403eb7..203e323 100644 --- a/test/lib/rails_ext/action_text_attachables_test.rb +++ b/test/lib/rails_ext/action_text_attachables_test.rb @@ -15,7 +15,7 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase test "from_node with a Rails 7 SGID" do gid = @user.to_gid.to_s - marshaled_gid = Base64.strict_encode64(Marshal.dump(gid)) + marshaled_gid = Base64.urlsafe_encode64(Marshal.dump(gid)) rails7_payload = { "_rails" => { "message" => marshaled_gid, "exp" => nil, "pur" => "attachable" } } rails7_message = Base64.strict_encode64(JSON.generate(rails7_payload)) rails7_sgid = "#{rails7_message}--invalidsignature"