Skip to content
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

session fixation #5373

Closed
firdausmaarof opened this issue Apr 16, 2021 · 4 comments
Closed

session fixation #5373

firdausmaarof opened this issue Apr 16, 2021 · 4 comments

Comments

@firdausmaarof
Copy link

Pre-check

  • Do not use the issues tracker for help or support, try Stack Overflow.
  • For bugs, do a quick search and make sure the bug has not yet been reported
  • If you found a security bug, do not report it through GitHub. Please send an e-mail to [email protected] instead.
  • Finally, be nice and have fun!

Environment

  • Ruby [2.4.10]
  • Rails [5.1.6]
  • Devise [4.4.3]

Current behavior

After i login, i copy the session id in the cookies. Open a new browser, and use the session id. it logged the user in.

Expected behavior

It supposed to not logged the user in using the same session id that i copied from a different browser.

@eliascaceresy
Copy link

I have the same problem!! Any solution?

@carlosantoniodasilva
Copy link
Member

Please read #5348 and https://guides.rubyonrails.org/security.html#replay-attacks-for-cookiestore-sessions. There's basically no way to avoid this for a valid session / cookie that's just copied and reused somewhere else. Thanks.

@patleb
Copy link

patleb commented Sep 6, 2022

I was looking at how devise mitigates the attack and to my surprise.. it didn't. Actually, one way to prevent this family of attacks is to keep a timestamp in the session and verify that :confirmed_at (or adding another field in the db to reset sessions) is before the current session timestamp.

This is actually a big deal to ignore scenarios like someone creating an account in advance with another user email, save the session. Then, the real user, at some point, confirms the account or resets the password or whatnot and, from that time, the malicious user could use the account at will.

@patleb patleb mentioned this issue Sep 6, 2022
@mcgha
Copy link

mcgha commented Feb 15, 2023

A solution I found while working on this:
As you mentioned, Devise doesn't do anything to prevent this, contrary to the Rails documentation. Calling reset_session will provide you a new session_id but it doesn't make the old one invalid.
I managed to mitigate the issue by setting an expiration date on the cookie in the session store. Devise will not authenticate an expired cookie. It doesn't quite fix the issue, but it's just mitigation.

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

No branches or pull requests

5 participants