2007-09-16 05:29:14 +08:00
|
|
|
import base64
|
2013-05-16 07:14:28 +08:00
|
|
|
import logging
|
2012-11-29 23:36:43 +08:00
|
|
|
import string
|
2015-01-28 20:35:27 +08:00
|
|
|
from datetime import datetime, timedelta
|
2007-09-16 05:29:14 +08:00
|
|
|
|
2008-06-23 13:08:07 +08:00
|
|
|
from django.conf import settings
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.contrib.sessions.exceptions import SuspiciousSession
|
2008-06-23 13:08:07 +08:00
|
|
|
from django.core.exceptions import SuspiciousOperation
|
2011-11-20 18:33:44 +08:00
|
|
|
from django.utils import timezone
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.utils.crypto import (
|
|
|
|
constant_time_compare, get_random_string, salted_hmac,
|
|
|
|
)
|
2017-04-22 01:52:26 +08:00
|
|
|
from django.utils.encoding import force_bytes
|
2014-01-21 04:15:14 +08:00
|
|
|
from django.utils.module_loading import import_string
|
2013-05-16 07:14:28 +08:00
|
|
|
|
2012-11-29 23:36:43 +08:00
|
|
|
# session_key should not be case sensitive because some backends can store it
|
|
|
|
# on case insensitive file systems.
|
|
|
|
VALID_KEY_CHARS = string.ascii_lowercase + string.digits
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-08-14 11:57:18 +08:00
|
|
|
class CreateError(Exception):
|
|
|
|
"""
|
|
|
|
Used internally as a consistent exception type to catch from save (see the
|
|
|
|
docstring for SessionBase.save() for details).
|
|
|
|
"""
|
|
|
|
pass
|
2008-06-23 13:08:07 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2016-01-09 00:08:08 +08:00
|
|
|
class UpdateError(Exception):
|
|
|
|
"""
|
|
|
|
Occurs if Django tries to update a session that was deleted.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2017-01-19 15:39:46 +08:00
|
|
|
class SessionBase:
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
|
|
|
Base class for all Session classes.
|
|
|
|
"""
|
|
|
|
TEST_COOKIE_NAME = 'testcookie'
|
|
|
|
TEST_COOKIE_VALUE = 'worked'
|
|
|
|
|
2016-04-20 16:36:59 +08:00
|
|
|
__not_given = object()
|
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def __init__(self, session_key=None):
|
|
|
|
self._session_key = session_key
|
|
|
|
self.accessed = False
|
|
|
|
self.modified = False
|
2014-01-21 04:15:14 +08:00
|
|
|
self.serializer = import_string(settings.SESSION_SERIALIZER)
|
2007-09-16 05:29:14 +08:00
|
|
|
|
|
|
|
def __contains__(self, key):
|
|
|
|
return key in self._session
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
return self._session[key]
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
self._session[key] = value
|
|
|
|
self.modified = True
|
|
|
|
|
|
|
|
def __delitem__(self, key):
|
|
|
|
del self._session[key]
|
|
|
|
self.modified = True
|
|
|
|
|
|
|
|
def get(self, key, default=None):
|
|
|
|
return self._session.get(key, default)
|
|
|
|
|
2016-04-20 16:36:59 +08:00
|
|
|
def pop(self, key, default=__not_given):
|
2007-10-20 18:12:59 +08:00
|
|
|
self.modified = self.modified or key in self._session
|
2016-04-20 16:36:59 +08:00
|
|
|
args = () if default is self.__not_given else (default,)
|
|
|
|
return self._session.pop(key, *args)
|
2007-09-16 05:29:14 +08:00
|
|
|
|
2007-12-02 23:27:29 +08:00
|
|
|
def setdefault(self, key, value):
|
|
|
|
if key in self._session:
|
|
|
|
return self._session[key]
|
|
|
|
else:
|
|
|
|
self.modified = True
|
|
|
|
self._session[key] = value
|
|
|
|
return value
|
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def set_test_cookie(self):
|
|
|
|
self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE
|
|
|
|
|
|
|
|
def test_cookie_worked(self):
|
|
|
|
return self.get(self.TEST_COOKIE_NAME) == self.TEST_COOKIE_VALUE
|
|
|
|
|
|
|
|
def delete_test_cookie(self):
|
|
|
|
del self[self.TEST_COOKIE_NAME]
|
2007-09-20 12:35:03 +08:00
|
|
|
|
Fixed #14445 - Use HMAC and constant-time comparison functions where needed.
All adhoc MAC applications have been updated to use HMAC, using SHA1 to
generate unique keys for each application based on the SECRET_KEY, which is
common practice for this situation. In all cases, backwards compatibility
with existing hashes has been maintained, aiming to phase this out as per
the normal deprecation process. In this way, under most normal
circumstances the old hashes will have expired (e.g. by session expiration
etc.) before they become invalid.
In the case of the messages framework and the cookie backend, which was
already using HMAC, there is the possibility of a backwards incompatibility
if the SECRET_KEY is shorter than the default 50 bytes, but the low
likelihood and low impact meant compatibility code was not worth it.
All known instances where tokens/hashes were compared using simple string
equality, which could potentially open timing based attacks, have also been
fixed using a constant-time comparison function.
There are no known practical attacks against the existing implementations,
so these security improvements will not be backported.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14218 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-15 04:54:30 +08:00
|
|
|
def _hash(self, value):
|
|
|
|
key_salt = "django.contrib.sessions" + self.__class__.__name__
|
|
|
|
return salted_hmac(key_salt, value).hexdigest()
|
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def encode(self, session_dict):
|
2017-01-25 04:31:57 +08:00
|
|
|
"Return the given session dictionary serialized and encoded as a string."
|
2013-08-22 08:12:19 +08:00
|
|
|
serialized = self.serializer().dumps(session_dict)
|
|
|
|
hash = self._hash(serialized)
|
|
|
|
return base64.b64encode(hash.encode() + b":" + serialized).decode('ascii')
|
2007-09-16 05:29:14 +08:00
|
|
|
|
|
|
|
def decode(self, session_data):
|
2012-08-29 02:59:56 +08:00
|
|
|
encoded_data = base64.b64decode(force_bytes(session_data))
|
Fixed #14445 - Use HMAC and constant-time comparison functions where needed.
All adhoc MAC applications have been updated to use HMAC, using SHA1 to
generate unique keys for each application based on the SECRET_KEY, which is
common practice for this situation. In all cases, backwards compatibility
with existing hashes has been maintained, aiming to phase this out as per
the normal deprecation process. In this way, under most normal
circumstances the old hashes will have expired (e.g. by session expiration
etc.) before they become invalid.
In the case of the messages framework and the cookie backend, which was
already using HMAC, there is the possibility of a backwards incompatibility
if the SECRET_KEY is shorter than the default 50 bytes, but the low
likelihood and low impact meant compatibility code was not worth it.
All known instances where tokens/hashes were compared using simple string
equality, which could potentially open timing based attacks, have also been
fixed using a constant-time comparison function.
There are no known practical attacks against the existing implementations,
so these security improvements will not be backported.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14218 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-15 04:54:30 +08:00
|
|
|
try:
|
|
|
|
# could produce ValueError if there is no ':'
|
2013-08-22 08:12:19 +08:00
|
|
|
hash, serialized = encoded_data.split(b':', 1)
|
|
|
|
expected_hash = self._hash(serialized)
|
2012-08-13 04:26:17 +08:00
|
|
|
if not constant_time_compare(hash.decode(), expected_hash):
|
2013-05-16 07:14:28 +08:00
|
|
|
raise SuspiciousSession("Session data corrupted")
|
Fixed #14445 - Use HMAC and constant-time comparison functions where needed.
All adhoc MAC applications have been updated to use HMAC, using SHA1 to
generate unique keys for each application based on the SECRET_KEY, which is
common practice for this situation. In all cases, backwards compatibility
with existing hashes has been maintained, aiming to phase this out as per
the normal deprecation process. In this way, under most normal
circumstances the old hashes will have expired (e.g. by session expiration
etc.) before they become invalid.
In the case of the messages framework and the cookie backend, which was
already using HMAC, there is the possibility of a backwards incompatibility
if the SECRET_KEY is shorter than the default 50 bytes, but the low
likelihood and low impact meant compatibility code was not worth it.
All known instances where tokens/hashes were compared using simple string
equality, which could potentially open timing based attacks, have also been
fixed using a constant-time comparison function.
There are no known practical attacks against the existing implementations,
so these security improvements will not be backported.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14218 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-15 04:54:30 +08:00
|
|
|
else:
|
2013-08-22 08:12:19 +08:00
|
|
|
return self.serializer().loads(serialized)
|
2013-05-16 07:14:28 +08:00
|
|
|
except Exception as e:
|
2011-03-31 01:35:22 +08:00
|
|
|
# ValueError, SuspiciousOperation, unpickling exceptions. If any of
|
|
|
|
# these happen, just return an empty dictionary (an empty session).
|
2013-05-16 07:14:28 +08:00
|
|
|
if isinstance(e, SuspiciousOperation):
|
2016-03-29 06:33:29 +08:00
|
|
|
logger = logging.getLogger('django.security.%s' % e.__class__.__name__)
|
2017-04-22 01:52:26 +08:00
|
|
|
logger.warning(str(e))
|
2011-03-31 01:35:22 +08:00
|
|
|
return {}
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2008-06-18 20:07:46 +08:00
|
|
|
def update(self, dict_):
|
|
|
|
self._session.update(dict_)
|
|
|
|
self.modified = True
|
|
|
|
|
|
|
|
def has_key(self, key):
|
2011-09-10 03:33:40 +08:00
|
|
|
return key in self._session
|
2008-06-18 20:07:46 +08:00
|
|
|
|
2011-11-28 01:52:24 +08:00
|
|
|
def keys(self):
|
|
|
|
return self._session.keys()
|
|
|
|
|
2008-06-18 20:07:46 +08:00
|
|
|
def values(self):
|
|
|
|
return self._session.values()
|
|
|
|
|
2011-11-28 01:52:24 +08:00
|
|
|
def items(self):
|
|
|
|
return self._session.items()
|
|
|
|
|
2008-08-14 11:57:30 +08:00
|
|
|
def clear(self):
|
2008-08-15 22:59:11 +08:00
|
|
|
# To avoid unnecessary persistent storage accesses, we set up the
|
|
|
|
# internals directly (loading data wastes time, since we are going to
|
|
|
|
# set it to an empty dict anyway).
|
|
|
|
self._session_cache = {}
|
|
|
|
self.accessed = True
|
2008-08-14 11:57:30 +08:00
|
|
|
self.modified = True
|
|
|
|
|
2013-08-19 13:36:36 +08:00
|
|
|
def is_empty(self):
|
2017-01-25 04:31:57 +08:00
|
|
|
"Return True when there is no session_key and the session is empty."
|
2013-08-19 13:36:36 +08:00
|
|
|
try:
|
2017-12-08 06:13:07 +08:00
|
|
|
return not self._session_key and not self._session_cache
|
2013-08-19 13:36:36 +08:00
|
|
|
except AttributeError:
|
|
|
|
return True
|
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def _get_new_session_key(self):
|
2017-01-25 04:31:57 +08:00
|
|
|
"Return session key that isn't being used."
|
2011-11-28 01:52:24 +08:00
|
|
|
while True:
|
2012-11-29 23:36:43 +08:00
|
|
|
session_key = get_random_string(32, VALID_KEY_CHARS)
|
2007-09-16 05:29:14 +08:00
|
|
|
if not self.exists(session_key):
|
2018-01-04 02:24:02 +08:00
|
|
|
return session_key
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2011-11-28 01:52:24 +08:00
|
|
|
def _get_or_create_session_key(self):
|
|
|
|
if self._session_key is None:
|
2007-09-16 05:29:14 +08:00
|
|
|
self._session_key = self._get_new_session_key()
|
2011-11-28 01:52:24 +08:00
|
|
|
return self._session_key
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2015-06-05 20:48:41 +08:00
|
|
|
def _validate_session_key(self, key):
|
|
|
|
"""
|
|
|
|
Key must be truthy and at least 8 characters long. 8 characters is an
|
|
|
|
arbitrary lower bound for some minimal key security.
|
|
|
|
"""
|
|
|
|
return key and len(key) >= 8
|
|
|
|
|
2011-11-28 01:52:24 +08:00
|
|
|
def _get_session_key(self):
|
2015-06-05 20:48:41 +08:00
|
|
|
return self.__session_key
|
|
|
|
|
|
|
|
def _set_session_key(self, value):
|
|
|
|
"""
|
|
|
|
Validate session key on assignment. Invalid values will set to None.
|
|
|
|
"""
|
|
|
|
if self._validate_session_key(value):
|
|
|
|
self.__session_key = value
|
|
|
|
else:
|
|
|
|
self.__session_key = None
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2011-11-28 01:52:24 +08:00
|
|
|
session_key = property(_get_session_key)
|
2015-06-05 20:48:41 +08:00
|
|
|
_session_key = property(_get_session_key, _set_session_key)
|
2007-09-16 05:29:14 +08:00
|
|
|
|
2008-08-15 03:43:08 +08:00
|
|
|
def _get_session(self, no_load=False):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Lazily load session from storage (unless "no_load" is True, when only
|
|
|
|
an empty dict is stored) and store it in the current instance.
|
2008-08-15 03:43:08 +08:00
|
|
|
"""
|
2007-09-16 05:29:14 +08:00
|
|
|
self.accessed = True
|
|
|
|
try:
|
|
|
|
return self._session_cache
|
|
|
|
except AttributeError:
|
2011-11-28 01:52:24 +08:00
|
|
|
if self.session_key is None or no_load:
|
2007-09-16 05:29:14 +08:00
|
|
|
self._session_cache = {}
|
|
|
|
else:
|
|
|
|
self._session_cache = self.load()
|
|
|
|
return self._session_cache
|
|
|
|
|
|
|
|
_session = property(_get_session)
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2012-10-28 03:32:50 +08:00
|
|
|
def get_expiry_age(self, **kwargs):
|
2012-10-28 01:18:03 +08:00
|
|
|
"""Get the number of seconds until the session expires.
|
|
|
|
|
2012-10-28 03:32:50 +08:00
|
|
|
Optionally, this function accepts `modification` and `expiry` keyword
|
|
|
|
arguments specifying the modification and expiry of the session.
|
2012-10-28 01:18:03 +08:00
|
|
|
"""
|
2012-10-28 03:32:50 +08:00
|
|
|
try:
|
|
|
|
modification = kwargs['modification']
|
|
|
|
except KeyError:
|
|
|
|
modification = timezone.now()
|
|
|
|
# Make the difference between "expiry=None passed in kwargs" and
|
|
|
|
# "expiry not passed in kwargs", in order to guarantee not to trigger
|
|
|
|
# self.load() when expiry is provided.
|
|
|
|
try:
|
|
|
|
expiry = kwargs['expiry']
|
|
|
|
except KeyError:
|
2012-10-28 01:18:03 +08:00
|
|
|
expiry = self.get('_session_expiry')
|
2012-10-28 03:32:50 +08:00
|
|
|
|
2008-06-08 04:28:06 +08:00
|
|
|
if not expiry: # Checks both None and 0 cases
|
|
|
|
return settings.SESSION_COOKIE_AGE
|
|
|
|
if not isinstance(expiry, datetime):
|
|
|
|
return expiry
|
2012-10-28 03:32:50 +08:00
|
|
|
delta = expiry - modification
|
2008-06-08 04:28:06 +08:00
|
|
|
return delta.days * 86400 + delta.seconds
|
|
|
|
|
2012-10-28 03:32:50 +08:00
|
|
|
def get_expiry_date(self, **kwargs):
|
|
|
|
"""Get session the expiry date (as a datetime object).
|
|
|
|
|
|
|
|
Optionally, this function accepts `modification` and `expiry` keyword
|
|
|
|
arguments specifying the modification and expiry of the session.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
modification = kwargs['modification']
|
|
|
|
except KeyError:
|
|
|
|
modification = timezone.now()
|
|
|
|
# Same comment as in get_expiry_age
|
|
|
|
try:
|
|
|
|
expiry = kwargs['expiry']
|
|
|
|
except KeyError:
|
|
|
|
expiry = self.get('_session_expiry')
|
|
|
|
|
2008-06-08 04:28:06 +08:00
|
|
|
if isinstance(expiry, datetime):
|
|
|
|
return expiry
|
2018-01-04 07:52:12 +08:00
|
|
|
expiry = expiry or settings.SESSION_COOKIE_AGE # Checks both None and 0 cases
|
2012-10-28 03:32:50 +08:00
|
|
|
return modification + timedelta(seconds=expiry)
|
2008-06-08 04:28:06 +08:00
|
|
|
|
|
|
|
def set_expiry(self, value):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Set a custom expiration for the session. ``value`` can be an integer,
|
2008-06-23 13:08:07 +08:00
|
|
|
a Python ``datetime`` or ``timedelta`` object or ``None``.
|
2008-06-08 04:28:06 +08:00
|
|
|
|
|
|
|
If ``value`` is an integer, the session will expire after that many
|
|
|
|
seconds of inactivity. If set to ``0`` then the session will expire on
|
|
|
|
browser close.
|
|
|
|
|
|
|
|
If ``value`` is a ``datetime`` or ``timedelta`` object, the session
|
|
|
|
will expire at that specific future time.
|
|
|
|
|
|
|
|
If ``value`` is ``None``, the session uses the global session expiry
|
|
|
|
policy.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
# Remove any custom expiration for this session.
|
2017-09-07 20:16:21 +08:00
|
|
|
try:
|
2008-06-08 04:28:06 +08:00
|
|
|
del self['_session_expiry']
|
2017-09-07 20:16:21 +08:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2008-06-08 04:28:06 +08:00
|
|
|
return
|
|
|
|
if isinstance(value, timedelta):
|
2011-11-20 18:33:44 +08:00
|
|
|
value = timezone.now() + value
|
2008-06-08 04:28:06 +08:00
|
|
|
self['_session_expiry'] = value
|
|
|
|
|
|
|
|
def get_expire_at_browser_close(self):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Return ``True`` if the session is set to expire when the browser
|
2008-06-08 04:28:06 +08:00
|
|
|
closes, and ``False`` if there's an expiry date. Use
|
|
|
|
``get_expiry_date()`` or ``get_expiry_age()`` to find the actual expiry
|
|
|
|
date/age, if there is one.
|
|
|
|
"""
|
|
|
|
if self.get('_session_expiry') is None:
|
|
|
|
return settings.SESSION_EXPIRE_AT_BROWSER_CLOSE
|
|
|
|
return self.get('_session_expiry') == 0
|
|
|
|
|
2008-08-14 11:57:46 +08:00
|
|
|
def flush(self):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Remove the current session data from the database and regenerate the
|
2008-08-14 11:57:46 +08:00
|
|
|
key.
|
|
|
|
"""
|
|
|
|
self.clear()
|
|
|
|
self.delete()
|
2013-08-19 13:36:36 +08:00
|
|
|
self._session_key = None
|
2008-08-14 11:57:46 +08:00
|
|
|
|
2008-08-21 21:54:53 +08:00
|
|
|
def cycle_key(self):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Create a new session key, while retaining the current session data.
|
2008-08-21 21:54:53 +08:00
|
|
|
"""
|
2017-04-12 08:35:17 +08:00
|
|
|
data = self._session
|
2008-08-21 21:54:53 +08:00
|
|
|
key = self.session_key
|
|
|
|
self.create()
|
|
|
|
self._session_cache = data
|
2016-01-09 00:08:08 +08:00
|
|
|
if key:
|
|
|
|
self.delete(key)
|
2008-08-21 21:54:53 +08:00
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
# Methods that child classes must implement.
|
2007-09-20 12:35:03 +08:00
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def exists(self, session_key):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Return True if the given session_key already exists.
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of SessionBase must provide an exists() method')
|
2007-09-16 05:29:14 +08:00
|
|
|
|
2008-08-14 11:57:18 +08:00
|
|
|
def create(self):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Create a new session instance. Guaranteed to create a new object with
|
2008-08-14 11:57:18 +08:00
|
|
|
a unique key and will have saved the result once (with empty data)
|
|
|
|
before the method returns.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of SessionBase must provide a create() method')
|
2008-08-14 11:57:18 +08:00
|
|
|
|
|
|
|
def save(self, must_create=False):
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Save the session data. If 'must_create' is True, create a new session
|
|
|
|
object (or raise CreateError). Otherwise, only update an existing
|
|
|
|
object and don't create one (raise UpdateError if needed).
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of SessionBase must provide a save() method')
|
2007-09-16 05:29:14 +08:00
|
|
|
|
2008-08-14 11:57:46 +08:00
|
|
|
def delete(self, session_key=None):
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Delete the session data under this key. If the key is None, use the
|
|
|
|
current session key value.
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of SessionBase must provide a delete() method')
|
2007-09-16 05:29:14 +08:00
|
|
|
|
|
|
|
def load(self):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Load the session data and return a dictionary.
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('subclasses of SessionBase must provide a load() method')
|
2012-10-28 05:12:08 +08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def clear_expired(cls):
|
|
|
|
"""
|
|
|
|
Remove expired sessions from the session store.
|
|
|
|
|
|
|
|
If this operation isn't possible on a given backend, it should raise
|
|
|
|
NotImplementedError. If it isn't necessary, because the backend has
|
|
|
|
a built-in expiration mechanism, it should be a no-op.
|
|
|
|
"""
|
2013-09-07 02:24:52 +08:00
|
|
|
raise NotImplementedError('This backend does not support clear_expired().')
|