Skip to content

Commit 06835f1

Browse files
Shaeliioquatix
authored andcommitted
Update cookie.rb to still allow old HMAC generation
I could be wrong, but I think that https://github.com/rack/rack/pull/1177/files is not backward compatible. It still allows to verify old sessions cookies with the `--$HMAC` format when using a set of a legacy options, but it doesn't allow to create cookies sessions with the old `--$HMAC` format, even with `legacy_generate_hmac` and `legacy_hmac_secret` are set. Comment in the code mentions this is backward compatible with the correct options, but still ``` if @Secrets.first session_data << "--#{generate_hmac(session_data, @Secrets.first)}" end ``` is removed and I don't see any other place where the `--$HMAC` could be set. This is adding it back.
1 parent dadcfe6 commit 06835f1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/rack/session/cookie.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def write_session(req, session_id, session, options)
266266
session = session.merge("session_id" => session_id)
267267
session_data = encode_session_data(session)
268268

269+
if @legacy_hmac_secret
270+
session_data << "--#{legacy_generate_hmac(session_data)}"
271+
end
272+
269273
if session_data.size > (4096 - @key.size)
270274
req.get_header(RACK_ERRORS).puts("Warning! Rack::Session::Cookie data size exceeds 4K.")
271275
nil

0 commit comments

Comments
 (0)