mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[3.1.x] Fixed #31895 -- Fixed crash when decoding invalid session data.
Thanks Matt Hegarty for the report. Regression ind4fff711d4. Backport of4376c2c7f8from master
This commit is contained in:
@@ -333,11 +333,16 @@ class SessionTestsMixin:
|
||||
self.assertEqual(self.session._legacy_decode(encoded), data)
|
||||
|
||||
def test_decode_failure_logged_to_security(self):
|
||||
bad_encode = base64.b64encode(b'flaskdj:alkdjf').decode('ascii')
|
||||
with self.assertLogs('django.security.SuspiciousSession', 'WARNING') as cm:
|
||||
self.assertEqual({}, self.session.decode(bad_encode))
|
||||
# The failed decode is logged.
|
||||
self.assertIn('corrupted', cm.output[0])
|
||||
tests = [
|
||||
base64.b64encode(b'flaskdj:alkdjf').decode('ascii'),
|
||||
'bad:encoded:value',
|
||||
]
|
||||
for encoded in tests:
|
||||
with self.subTest(encoded=encoded):
|
||||
with self.assertLogs('django.security.SuspiciousSession', 'WARNING') as cm:
|
||||
self.assertEqual(self.session.decode(encoded), {})
|
||||
# The failed decode is logged.
|
||||
self.assertIn('Session data corrupted', cm.output[0])
|
||||
|
||||
def test_actual_expiry(self):
|
||||
# this doesn't work with JSONSerializer (serializing timedelta)
|
||||
|
||||
Reference in New Issue
Block a user