Conversation
Author
|
I checked the two failing CI jobs. They appear unrelated to this patch:
The jobs that exercise the supported Python/OS matrix, style, docs, and typing passed. I kept this PR scoped to the session fallback validation rather than mixing in dependency/test-suite maintenance changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SECRET_KEY_FALLBACKSis documented and implemented as a list of old signing keys. If an app accidentally configures it as a scalar string or bytes value, the session interface currently callskeys.extend(fallbacks), which expands the value into one-character or one-byte fallback keys before constructing theitsdangerousserializer.This rejects scalar
strandbytesfallback values before building the key list, while preserving the existing list-based key rotation behavior.Security impact
For an affected app using signed cookie sessions, a misconfigured value such as
SECRET_KEY_FALLBACKS = "old-secret"could make Flask accept cookies signed with a single-character fallback key such as"o". I verified the pre-fix behavior with a cookie signed using"o"; the session loaded successfully whenSECRET_KEY_FALLBACKSwas a string. After this change, the same request raises a configurationTypeErrorinstead of accepting the forged session.This can also happen through environment configuration if a value is supplied as a plain string instead of JSON/list syntax.
Validation
python3 -m py_compile src/flask/sessions.py tests/test_basic.py/tmp/flask-verify-venv/bin/ruff check src/flask/sessions.py tests/test_basic.py/tmp/flask-verify-venv/bin/ruff format --check src/flask/sessions.py tests/test_basic.py/tmp/flask-verify-venv/bin/python -m pytest tests/test_basic.py::test_session_secret_key_fallbacks tests/test_basic.py::test_session_secret_key_fallbacks_rejects_string_or_bytes -q493 passed in 6.36s