Restrict Django sessions to IP and/or user agent.
Restricts Django sessions to IP and/or user agent.
If the IP or user agent changes after creating the session, the a 400 response is given to the request, the session is flushed (all session data deleted, new session created) and a warning is logged. The goal of this middleware is to make it harder for an attacker to use a session ID they obtained. It does not make abuse of session IDs impossible.
For compatibility with IPv6 privacy extensions, by default only the first 64 bits of an IPv6 address are checked.
The full documentation is at https://django-restricted-sessions.readthedocs.org.
pip install django-restricted-sessions
Then add it to your middleware after SessionMiddleware:
MIDDLEWARE_CLASSES = [ .... 'django.contrib.sessions.middleware.SessionMiddleware', # 'django.contrib.auth.middleware.AuthenticationMiddleware', 'restrictedsessions.middleware.RestrictedSessionsMiddleware', .... ]
When RESTRICTEDSESSIONS_AUTHED_ONLY setting enabled ensure this middleware is added after AuthenticationMiddleware such that the request.user is present.
- Updated Django support to 1.11, 2.2 and 3.0.
- Fixed issues when X_FORWARDED_FOR contains multiple addresses.
- For Django 1.10+ support, changed from object to django.utils.deprecation.MiddlewareMixin
- Added PyPI trove classifiers for Django versions and more Python versions
- Updated travis.yml for more Python versions
- Fixed an exception that could occur when non-utf8 bytes were included in user agent strings.
- Version bump to avoid PyPI’s duplicate filename ban.
- Added support to redirect to known view, or use custom status code settings.
- Added support for ignoring unauthenticated sessions.
- Fixed short circuit when REMOTE_ADDR was unknown.
- Dropped support for older Python versions: now requires 2.7, 3.3 or newer, with Django 1.8.
- Resolved exception being raised when session switches from IPv4 to IPv6
- Python 3.4 support
- Added missing netaddr requirement to setup.py.
- First release on PyPI.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size django_restricted_sessions-0.3.0-py2.py3-none-any.whl (4.5 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size django-restricted-sessions-0.3.0.tar.gz (6.8 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for django_restricted_sessions-0.3.0-py2.py3-none-any.whl
Hashes for django-restricted-sessions-0.3.0.tar.gz