-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rack::Session::Redis#generate_unique_sid's unique session key generation logic does not work #69
Comments
@hogelog Given one uses the default |
Unfortunately, I don't know exactly how often ID collisions happen, as I noticed it while looking at the code. In default, sid (= public session id) is (Assuming that SecureRandom generates perfectly uniformly) SHA256 is hash function digesting to 256 bits. If SHA256 is a perfect hash function without bias, then a 256-bit input would be hashed to a 256-bit value without collision. Ofcource there are no perfect random generator and hash function algorightms, real collision rate would be more often. But, in any case, collision rate would be not so high. |
On the other hand, the code at https://github.com/redis-store/redis-rack/blob/v2.1.4/lib/rack/session/redis.rb#L23 does not seem to be working properly at the moment. I am thinking of sending a fix along with tests. |
@hogelog i just merged your changes to redis-store, wondering if that helps any with this issue? |
Rack::Session::Redis#generate_unique_sid
is a method that generates new unique session key that it does not conflict with an existing session key.But it seems does not work well after #37 PR.
session.empty?
.session
is always empty hash.Reproduction
I checked with the following code, which is prone to session key collisions.
Procedure
ruby app.rb
session[:access]
increases with each access.ruby app.rb
application and relaunch.session[:access]
is initialized.session
is shared with first browser and secret browser.The above situation occurs even with correct random number generation logic, although the collisions are fewer.
How to fix
Revert #37 is easy way, maybe.
If you want to avoid that, it would require a more complicated modification.
The text was updated successfully, but these errors were encountered: