Skip to content

Conversation

@hieuk09
Copy link

@hieuk09 hieuk09 commented Aug 7, 2025

Close #52

@ioquatix
Copy link
Member

ioquatix commented Oct 5, 2025

This looks okay to me. It seems robust to compare with the original value. @jeremyevans do you have any opinion on this?

@ioquatix
Copy link
Member

ioquatix commented Oct 5, 2025

For reference, I did something like this in the past:

https://github.com/socketry/utopia/blob/main/lib/utopia/session/lazy_hash.rb

Tracking whether any changes were made. But if you changed it to a new value and then back to the original, my code would not pick that up, but this PR would.

@ioquatix ioquatix force-pushed the bug/fix-encryption branch from 06ff52c to b086a5b Compare October 5, 2025 11:33
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my thoughts from a brief review. Note that I don't follow rack-session development, so this is not a particularly informed review.

Comment on lines 263 to 265
return if request.session.to_h == request.get_header(RACK_SESSION_WAS) &&
!request.get_header(RACK_SESSION_OPTIONS).fetch(:renew, false) &&
!cookie[:expires]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reverse the order of operations here. Only do the request.session conversion if the other two cheaper checks pass.

As mentioned in the other comment, instead of request.session.to_h, I would compare using marshal/json to avoid issues when modifying nested structures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opt to compare using ruby object here to avoid ordering mismatch that could happen during marshal/json. I think we don't intend to modify RACK_SESSION_WAS, I hope that could work in this case. Please let me know what you think.

@hieuk09
Copy link
Author

hieuk09 commented Oct 7, 2025

@jeremyevans Thanks for the review. I have updated the code in 445c2d1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set-Cookie header is set in response when valid cookies are sent in headers

3 participants