Open
Conversation
* don't bother encrypting the IV (?!) * use the same encryption key for the encryption as for the HMAC (easy to configure, since it's the same as for normal CookieStore) * compress the session before encrypting it (optional, will skip compression if it actually makes it larger) * use AES 128 CBC (AES 256 is actually *weaker*, due to a known attack on it), which also reduces the cookie size due to a smaller IV and less padding * use URI-safe base64 encoding to not waste space percent-encoding characters in the cookie * use . as the separator between cookie fields (instead of -, which is now a part of the base64 encoding) * if :expire_after is provided, add a timestamp to the cookie that's included in the HMAC to allow for secure expiration of cookies (preventing session replay attacks after the expiration of the cookie) * don't re-set the cookie on every request if the session hasn't changed (unless :expire_after is in use, in which case do it every 5 minutes by default in order to refresh the timestamp)
Owner
|
Very nice! But why not encrypt the IV? Is it supposed to be public information? I'm opposed to removing the "It is prone to session replay attacks" sentence from the README. You are less prone now but not completely invulnerable. Attackers can still replay sessions within the timeout period. |
Author
|
Because it's a waste of CPU cycles, adds unnecessary complexity, and does not add any "real" security (an IV is completely random data anyway; encrypting the randomness doesn't make it any more random, nor increase the security of bruteforcing the encrypted data): http://stackoverflow.com/questions/6167114/protect-encrypt-initialization-vector I'll adjust the readme re: session replay attacks. |
Include more details on still being vulnerable to session replay attacks, just less vulnerable.
test plan: * set :expire_after, but also set :expires to nil for session expiration of the real cookie * it shouldn't give a page error when the cookie expires
Options is now a class variable that you can change during call time. This way you can set attributes on the options hash. In this case we ensure the options hash gets the option to set :expire_after
Allow options to be changed.
the timestamp being used is refreshed every so often and doesn't actually indicate the *start* of the session
record session_refreshed_at
the timestamp stored in the encrypted cookie already represents the "session_refreshed_at" value. in 1.0.3 we incorrectly interpreted it as a "expires_at" value, as if it already included the expire_after value
fix calculation of session_refreshed_at timestamp
update to work with rails 3.2
allow setting expire_after before unmarshalling
fix deprecation warnings in Ruby 2.1
catch exceptions unmarshalling data
Ruby 2.4 validates the encryption key length is exactly the correct size, instead of just long enough. but be careful, because we still use the secret for the HMAC, which can take a key of any length. so only truncate what goes to encryption, not what goes to HMAC
fix encryption for Ruby 2.4
keys are strings; don't use a symbol for the timestamp key
fix refreshing the session on every request
rails/rails@92ec9f2 refs #CNVS-49218
allow rails 6.1
Allow rails 7.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(easy to configure, since it's the same as for normal CookieStore)
compression if it actually makes it larger)
attack on it), which also reduces the cookie size due to a smaller
IV and less padding
characters in the cookie
is now a part of the base64 encoding)
included in the HMAC to allow for secure expiration of cookies
(preventing session replay attacks after the expiration of the
cookie)
changed (unless :expire_after is in use, in which case do it every
5 minutes by default in order to refresh the timestamp)