Arnoud
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
+1.
1) We need a way to handle existing sessions when upgrading to the new
Django w/ this support. I think the most natural support for the
validation is
auth.get_user:
https://code.djangoproject.com/browser/django/trunk/django/contrib/auth/__init__.py?rev=16539#L94
to check the hash before returning.
2) I don't think the user should be logged out of their own session
when changing the password, and so we'd need to update the active
session on its way back to the user.
This is messier - we'd need to detect when the password changed
(User.set_password called?) and update the related request session, if
any. That may be best accomplished through a signal fired when the
password is changed and handled in session.
On 01/08/2012 03:57 PM, Arnoud van Heuvelen wrote:
[snip]
> 2) Build a relation table that links the sessions to the users. (Or
> use a CSV in the user object.) This could be done completely in the
> auth package. Downside is that we have to create a new table. Upside
> is again, that we could invalidate sessions on password change.
[snip]
> My favourite is option 2 for now. It seems the most resource friendly,
> even though we need to save more data. I don't know what Django's
> policy on adding tables is though.
This is not an option because the database session backend is only one
of many session backends.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk8LD1IACgkQ8W4rlRKtE2eHmgCbBx/7FlOHfi32Cr1pNWa4mKsW
Ca0An1rB+T9fwFwdlHzEmwj/PxTxIAd3
=Mj2V
-----END PGP SIGNATURE-----
On 01/09/2012 09:01 AM, Carl Meyer wrote:
> This is not an option because the database session backend is only one
> of many session backends.
Oh, never mind - I misunderstood the proposal. This wouldn't be
dependent on using the database session backend if its done entirely in
the auth app and based on the session key. It would, however, require a
database check on every session access, meaning the value of using a
faster session backend would be lost. Thus I still think it's not
feasible, and (if anything is to be done here) a solution like #3 that
stores extra data in the session itself is preferable.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk8LEGQACgkQ8W4rlRKtE2faiwCfUhQg9MouUnkGpYWec7WI1VJL
C7UAnjgEIiAgruPSPnlEZfucyRWmxbV3
=Jpx9
-----END PGP SIGNATURE-----
I'm not sure that invalidating session based on last password change is the right thing to do. If the password has been compromised, this effectively enables an active attacker to deny access to the legitimate user. In case of Django admin site this can be quite disruptive as there is no password recovery option by default. And if superuser password has been stolen, it takes only few clicks to create another superuser account or to grant someone superuser privileges. Password change seems to be a rather weak defense in this case.
Session invalidation based on password change would only be effective is someone is passively spying using a compromised password.
This is achievable with very little work, and no changes to core. We
implemented this feature for different reasons, but I see no reason
why you cannot make it do what you wanted it to do.
Basically:
Use a database session backend.
Define a new model for holding session references:
class SessionAudit(models.Model):
user = models.ForeignKey(User)
session = models.ForeignKey(django.contrib.sessions.models.Session)
ip_address = models.IPAddressField()
user_agent = models.TextField()
modified = models.DateTimeField(auto_now=True,)
created = models.DateTimeField(auto_now_add=True,)
Hook into django.contrib.auth.signals.{user_logged_in,user_logged_out}
and {create,remove} SessionAudit objects appropriately.
You now have, linked to the user, a list of their active sessions. If
you need to log out all but the current session, you simply need to
destroy the appropriate Sessions, as found from the SessionAudit
model.
As a final bit of clean up, when you destroy your sessions, you should
also destroy the related SessionAudit.
If you want to talk more about this approach, I think we are firmly in
django-users@ ground now, as this is simple BI.
Cheers
Tom