-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Add session methods to handle destruction and regeneration #1600
Comments
This seems to be specific to session interfaces that need a session id, and those two examples you gave seem to be handling it already. What do we gain by adding this to Flask? The default session doesn't use a session id, and can be wiped with |
Ah, good point. I think the benefit of implementing it in Flask (even as On a side note, |
Removing the cookie doesn't actually seem to be part of the security, only clearing the data or changing the id matter. The cookie is removed if the dict is empty, so the subclass could just override |
In a session id context, regenerate does more than change the value of the We perform this so that if the session id and its HMAC are known by an attacker, then they cannot access anything about the old session as well (e.g. maybe there's a tracking id in it).
|
I feel like I should mention why I am opposed to using cookie based sessions (i.e. storing session as a cookie JSON blob).
|
OK, thanks for the detailed report. I don't feel that I understand the issue enough to make a change. If you'd be willing to create a PR including a short summary in the docs and a test case, I'd be happy to review it. I still vaguely feel like there's better solutions that don't require changes, such as basing the hash for a session id on a secret that can be changed for each user, or tracking a list of valid ids for each user, but I can't think of any strong arguments against this. |
Ah, damn =( Please re-review the OWASP page -- it should clarify the topic some more: https://www.owasp.org/index.php/Session_fixation I will create a PR in a bit. I guess I am so adamant about this because a framework should be forward thinking for users -- similar to how we have With respect to changing the session id hash, people could use things like an IP address as part of the salt. But the generic salt will likely do the trick. Usually these compromises occur less from guessing via brute force (since rate limiting would block that) and more from somehow setting the session id (e.g. via a compromised subdomain which allows setting a |
Started on a PR and I see a few approaches but none seem appealing.
|
Why not use |
It might be a strawman but I think there's a reason that Flask has |
True, maybe it can run outside an app context (or it's from the time where there was no app context but just a request context). Anyway, |
Ah, good point. JSON serialization seems fine but pickle is polluted.
I guess that forces us to always use: app.regenerate_session(session)
app.destroy_session(session) |
We have been using
flask-session
for our sessions and noticed that there were no easy methods onflask
orflask-session
to handle session destruction/regeneration. These are practical as they aid in preventing session fixation attacks (e.g. when someone knows your session id and it doesn't get changed on login so they can reuse your session):https://www.owasp.org/index.php/Session_fixation
We saw that
flask-kvsession
has some logic for this:https://github.com/mbr/flask-kvsession/blob/0.6.2/flask_kvsession/__init__.py#L89-L124
but we were already invested into
flask-session
(addedsha256
signing support) that we decided to implement similar logic there as well:pallets-eco/flask-session#27
However, I'm not sure that's the ideal interface. I think the final product would look something more like
which in turn call
flask.session_interface.destroy_session(self, app, session)
andflask.session_interface.regenerate_session(self, app, session)
.What are your thoughts on this?
The text was updated successfully, but these errors were encountered: