티스토리 수익 글 보기

티스토리 수익 글 보기

[1.8.x] Fixed incorrect session.flush() in cached_db session backend. · django/django@31cb25a · GitHub
Skip to content
/ django Public

Commit 31cb25a

Browse files
committed
[1.8.x] Fixed incorrect session.flush() in cached_db session backend.
This is a security fix; disclosure to follow shortly. Thanks Sam Cooke for the report and draft patch.
1 parent 2b2a215 commit 31cb25a

File tree

3 files changed

+19
2
lines changed

3 files changed

+19
2
lines changed

django/contrib/sessions/backends/cached_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def flush(self):
7979
"""
8080
self.clear()
8181
self.delete(self.session_key)
82-
self._session_key = ''
82+
self._session_key = None
8383

8484
# At bottom to avoid circular import
8585
from django.contrib.sessions.models import Session # isort:skip

docs/releases/1.8.2.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@ Django 1.8.2 release notes
44

55
*Under development*
66

7-
Django 1.8.2 fixes several bugs in 1.8.1.
7+
Django 1.8.2 fixes a security issue and several bugs in 1.8.1.
8+
9+
Fixed session flushing in the ``cached_db`` backend
10+
===================================================
11+
12+
A change to ``session.flush()`` in the ``cached_db`` session backend in Django
13+
1.8 mistakenly sets the session key to an empty string rather than ``None``. An
14+
empty string is treated as a valid session key and the session cookie is set
15+
accordingly. Any users with an empty string in their session cookie will use
16+
the same session store. ``session.flush()`` is called by
17+
``django.contrib.auth.logout()`` and, more seriously, by
18+
``django.contrib.auth.login()`` when a user switches accounts. If a user is
19+
logged in and logs in again to a different account (without logging out) the
20+
session is flushed to avoid reuse. After the session is flushed (and its
21+
session key becomes ``''``) the account details are set on the session and the
22+
session is saved. Any users with an empty string in their session cookie will
23+
now be logged into that account.
824

925
Bugfixes
1026
========

tests/sessions_tests/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def test_flush(self):
162162
self.session.flush()
163163
self.assertFalse(self.session.exists(prev_key))
164164
self.assertNotEqual(self.session.session_key, prev_key)
165+
self.assertIsNone(self.session.session_key)
165166
self.assertTrue(self.session.modified)
166167
self.assertTrue(self.session.accessed)
167168

0 commit comments

Comments
 (0)