Skip to content
Myr

Merge branch 'stable'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents bc14349, bbaf133 · Browse files · 4 files+24 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+24 added−11 removed

  • tests:+11 added−4 removed
  • other:+13 added−7 removed

4 files+24 added−11 removed

modified:docs/config.rst+6 added-3 removed
125 unmodified lines
126 Default: ``None``127128.. py:data:: SECRET_KEY_FALLBACKS129130 A list of old secret keys that can still be used for unsigning, most recent131 first. This allows a project to implement key rotation without invalidating132 active sessions or other recently-signed secrets.130 A list of old secret keys that can still be used for unsigning. This allows131 a project to implement key rotation without invalidating active sessions or132 other recently-signed secrets.133134 Keys should be removed after an appropriate period of time, as checking each135 additional key adds some overhead.136137 Order should not matter, but the default implementation will test the last138 key in the list first, so it might make sense to order oldest to newest.139140 Flask's built-in secure cookie session supports this. Extensions that use141 :data:`SECRET_KEY` may not support this yet.142143 Default: ``None``
696 unmodified lines
modified:src/flask/sessions.py+2 added-1 removed
316 unmodified lines
317 def get_signing_serializer(self, app: Flask) -> URLSafeTimedSerializer | None:318 if not app.secret_key:319 return None320321 keys: list[str | bytes] = [app.secret_key]321 keys: list[str | bytes] = []322323 if fallbacks := app.config["SECRET_KEY_FALLBACKS"]:324 keys.extend(fallbacks)325326 keys.append(app.secret_key) # itsdangerous expects current key at top327 return URLSafeTimedSerializer(328 keys, # type: ignore[arg-type]329 salt=self.salt,330 serializer=self.serializer,
69 unmodified lines
modified:tests/test_basic.py+11 added-4 removed
379 unmodified lines
380 @app.get("/")381 def get_session() -> dict[str, t.Any]:382 return dict(flask.session)383384 # Set session with initial secret key384 # Set session with initial secret key, and two valid expiring keys385 app.secret_key, app.config["SECRET_KEY_FALLBACKS"] = (386 "0 key",387 ["-1 key", "-2 key"],388 )389 client.post()390 assert client.get().json == {"a": 1}391 # Change secret key, session can't be loaded and appears empty388 app.secret_key = "new test key"392 app.secret_key = "? key"393 assert client.get().json == {}390 # Add initial secret key as fallback, session can be loaded391 app.config["SECRET_KEY_FALLBACKS"] = ["test key"]394 # Rotate the valid keys, session can be loaded395 app.secret_key, app.config["SECRET_KEY_FALLBACKS"] = (396 "+1 key",397 ["0 key", "-1 key"],398 )399 assert client.get().json == {"a": 1}400401402def test_session_expiration(app, client):
1542 unmodified lines
modified:CHANGES.rst+5 added-3 removed
7 unmodified lines
89Version 3.1.110-------------1112Unreleased12Released 2025-05-131314- Fix signing key selection order when key rotation is enabled via15 ``SECRET_KEY_FALLBACKS``. :ghsa:`4grg-w6v8-c28g`14- Fix type hint for `cli_runner.invoke`. :issue:`5645`16- Fix type hint for ``cli_runner.invoke``. :issue:`5645`17- ``flask --help`` loads the app and plugins first to make sure all commands16 are shown. :issue:5673`18 are shown. :issue:`5673`19- Mark sans-io base class as being able to handle views that return20 ``AsyncIterable``. This is not accurate for Flask, but makes typing easier21 for Quart. :pr:`5659`22
1599 unmodified lines