def post_logout(user):
try:
import os
os.unlink(response.session_filename) # Clear the session from disk
except OSError:
pass
session.renew(clear_session=True) # Clear the memory/Storage object.
auth.settings.logout_onlogout = post_logout
session.renew() before unlink - since original session_filename is lost on renew
(This is related to security issue - I've explained the security issue in detail to Massimo and anthony separately)
I want the session to be "invalid" as soon as after user logs out (as well as after certain period of inactivity)
This is "supposed to be" default behaviour - but somehow doesn't work.
What I want is something like sessions2trash.py script - except that file should deleted right away - even if the session has not expired.
Currently I'm using something like following. Please suggest correct way to handle this (I know this works only for file based sessions, but that is OK)
def post_logout(user):
try:
import os
os.unlink(response.session_filename)# Clear the session from disk
except OSError:
pass
session.renew(clear_session=True) # Clear the memory/Storage object.
On Tuesday, October 14, 2014 2:18:05 PM UTC-4, Mandar Vaze wrote:(This is related to security issue - I've explained the security issue in detail to Massimo and anthony separately)
I want the session to be "invalid" as soon as after user logs out (as well as after certain period of inactivity)
This is "supposed to be" default behaviour - but somehow doesn't work.
In the current version of web2py, the default behavior is that upon logout, the session is cleared and renewed (i.e., a new session ID is issued). However, it does not delete the old session file.
When you say it "somehow doesn't work," do you just mean the old session file remains, or is something else not working?
What I want is something like sessions2trash.py script - except that file should deleted right away - even if the session has not expired.
Currently I'm using something like following. Please suggest correct way to handle this (I know this works only for file based sessions, but that is OK)
def post_logout(user):
try:
import os
os.unlink(response.session_filename)# Clear the session from disk
except OSError:
pass
session.renew(clear_session=True) # Clear the memory/Storage object.
You shouldn't need that last line, as the logout function already does exactly that by default.
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/j-GwnDc0G6g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
In the current version of web2py, the default behavior is that upon logout, the session is cleared and renewed (i.e., a new session ID is issued). However, it does not delete the old session file.When you say it "somehow doesn't work," do you just mean the old session file remains, or is something else not working?Yes. Session file does not get deleted.The side effect of session file remaining on the disk is that if the "hijacked" session ID is used by the attacker - then "somehow" contents of the session file on the disk are reused (even if session contents from memory (Storage object) are cleaned) Thus allowing the attacker access to logged in page without actually having to login.
BTW - which method gets invoked when session has "expired" ?Is there a "hook" where I can add the code to delete the session file - in addition to post_logout ?
Yes. Session file does not get deleted.The side effect of session file remaining on the disk is that if the "hijacked" session ID is used by the attacker - then "somehow" contents of the session file on the disk are reused (even if session contents from memory (Storage object) are cleaned) Thus allowing the attacker access to logged in page without actually having to login.
It may be worth having web2py delete the file (or database record in the case of database based sessions) automatically upon session.renew(). Maybe submit a Google Code issue about this.
browser will no longer transmit session cookies for old sessions).
In any case, there is no process that can monitor sessions/logins for expiration automatically (i.e., no place for a "hook"). The only "events" that the framework can respond to are requests, but an inactive client is not making any requests, so there would be nothing to trigger an expiration check.
To prevent session hijacking,
keep all logged in activity (including the login itself) over HTTPS.
If you're still concerned, delete the session file upon logout (as you are now doing)
and run sessions2trash periodically.
# Delete session in a module (move to the modules folder)
from sessions2trash import single_loop
def delete_sessions():
single_loop()
Trying to delete the session file at the precise instant of login expiration will add little to overall security.
Anthony
--
browser will no longer transmit session cookies for old sessions).But this is "normal" case - attacker can use/transmit "session cookies for old sessions" (which is where the whole discussion started)
In any case, there is no process that can monitor sessions/logins for expiration automatically (i.e., no place for a "hook"). The only "events" that the framework can respond to are requests, but an inactive client is not making any requests, so there would be nothing to trigger an expiration check.I understand. I am not looking for "process".I want to know which place in web2py code "determines" that for a normal request - session has expired and user should be redirected to "login" page - before the requested page is served ? (It attaches appropriate _next to the login form - so that after successful authentication - user is taken to the page s/he requested)
Will adding following (from sessions2trash.py docstring) be better if called immediately after successful login ?
This IMO ensures that session files are deleted after login attempt - especially when login was "forced" by the web2py framework due to expired session
# Delete session in a module (move to the modules folder)
from sessions2trash import single_loop
def delete_sessions():
single_loop()
I was simply pointing out that sessions do not technically expire on the server side. The browser expires sessions by ceasing to return the session cookie. If an attacker steals the cookie and keeps sending it, then the server does nothing to expire the session. However, Auth logins can expire, but that is a different matter.
that's why the whole thing goes away behind SSL. Expiring a session on logout is better than leaving it as it is, but even in that case while userA is logged in there's NO way to prevent a MITM from someone else.
On Saturday, October 18, 2014 12:18:30 AM UTC+2, Anthony wrote:On Friday, October 17, 2014 5:51:18 PM UTC-4, Dave S wrote:
On Friday, October 17, 2014 1:15:39 PM UTC-7, Anthony wrote:I was simply pointing out that sessions do not technically expire on the server side. The browser expires sessions by ceasing to return the session cookie. If an attacker steals the cookie and keeps sending it, then the server does nothing to expire the session. However, Auth logins can expire, but that is a different matter.
What's the model for an attacker stealing a cookie? Does it require access to the user's machine, or would a man-in-the-middle attack (with a wild proxy, for instance) work?
Can be done via MITM attack.
--