Skip to content

Comments

feat(auth): session fallback upgrade (swev-id: django__django-16631)#515

Open
casey-brooks wants to merge 1 commit intodjango__django-16631from
noa/issue-510
Open

feat(auth): session fallback upgrade (swev-id: django__django-16631)#515
casey-brooks wants to merge 1 commit intodjango__django-16631from
noa/issue-510

Conversation

@casey-brooks
Copy link

Issue

Observed Failure (pre-fix)

FAIL: test_session_auth_hash_validated_against_fallbacks_and_upgraded (auth_tests.test_session_auth_hash_fallbacks.SessionAuthHashFallbackTests.test_session_auth_hash_validated_against_fallbacks_and_upgraded)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/auth_tests/test_session_auth_hash_fallbacks.py", line 37, in test_session_auth_hash_validated_against_fallbacks_and_upgraded
    self.assertTrue(response.wsgi_request.user.is_authenticated)
AssertionError: False is not true

Reproduction Steps

  1. Checkout django__django-16631 without this patch.
  2. Apply tests/auth_tests/test_session_auth_hash_fallbacks.py from this branch.
  3. Run PYTHONPATH=$PWD .venv/bin/python tests/runtests.py auth_tests.test_session_auth_hash_fallbacks --parallel=1.

Fix Summary

  • Iterate session auth hash validation across SECRET_KEY and SECRET_KEY_FALLBACKS when using the default AbstractBaseUser.get_session_auth_hash implementation.
  • Transparently upgrade sessions issued under a fallback secret by cycling the key and re-seeding _auth_user_hash under the active secret.
  • Consolidate the session hash key salt in SESSION_AUTH_HASH_KEY_SALT for reuse across fallback validation.
  • Add regression coverage for fallback validation, upgrade behavior, mismatch handling, missing fallbacks, and custom hash overrides.

Testing

  • PYTHONPATH=$PWD .venv/bin/python tests/runtests.py auth_tests --parallel=1
  • .venv/bin/flake8 django/contrib/auth/__init__.py django/contrib/auth/base_user.py tests/auth_tests/test_session_auth_hash_fallbacks.py

CI

  • Not run (per instructions).

@casey-brooks casey-brooks requested a review from a team December 24, 2025 17:08
@casey-brooks
Copy link
Author

Tests & Lint Summary:

  • PYTHONPATH=/workspace/django .venv/bin/python tests/runtests.py auth_tests --parallel=1 (610 passed, 0 failed)
  • .venv/bin/flake8 django/contrib/auth/init.py django/contrib/auth/base_user.py tests/auth_tests/test_session_auth_hash_fallbacks.py (no issues)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting the default test site; matches current post_syncdb behavior.

@casey-brooks
Copy link
Author

Test & Lint Summary

  • PYTHONPATH=$PWD python tests/runtests.py auth_tests.test_session_auth_hash_fallbacks --parallel=1: passed (4 passed, 0 failed, 0 skipped)
  • PYTHONPATH=$PWD python tests/runtests.py auth_tests.test_basic auth_tests.test_middleware auth_tests.test_views --parallel=1: passed (129 passed, 0 failed, 0 skipped)
  • PYTHONPATH=$PWD python tests/runtests.py auth_tests --parallel=1: passed (600 passed, 0 failed, 10 skipped)
  • flake8 django/contrib/auth/__init__.py django/contrib/auth/base_user.py tests/auth_tests/test_session_auth_hash_fallbacks.py: lint clean (no errors)

@rowan-stein rowan-stein changed the base branch from django__django-16631 to main January 11, 2026 20:34
@rowan-stein rowan-stein changed the base branch from main to django__django-16631 January 12, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SECRET_KEY_FALLBACKS is not used for sessions

2 participants