How can auth can be configured or modified to disallow user sessions if the user's IP is not the same IP that he logged in with ? I really try to protect my Django site from XSS as much as I can. But I never can be sure that I covered all the bases. If worst comes to worst and someone is able to put some XSS in my site, at least this could prevent him from hijacking existing user sessions..
views:
27answers:
1
A:
In your User model class create an IP field that stores the IP address of the request.
original_ip_address = request.META['REMOTE_ADDR']
then before serving a view simply check the current request with the stored ip:
if request.META['REMOTE_ADDR'] == ip_from_database: `
# Do something
else:
#redirect to login
you can make the above a function that is always called before anything else in a view.
Ali
2010-07-31 21:09:45
Make sure to update the ip on every successful login attempt or to delete it after a logout, else they might not be able to come back.
Ali
2010-08-01 01:51:32