secret key rotation: fix key list ordering
The `itsdangerous` serializer interface[1] expects keys to be provided with the oldest key at index zero and the active signing key at the end of the list. We document[2] that `SECRET_KEY_FALLBACKS` should be configured with the most recent first (at index zero), so to achieve the expected behaviour, those should be inserted in reverse-order at the head of the list. [1] - https://itsdangerous.palletsprojects.com/en/stable/serializer/#itsdangerous.serializer.Serializer [2] - https://flask.palletsprojects.com/en/stable/config/#SECRET_KEY_FALLBACKS
This commit is contained in:
parent
941efd4a36
commit
fb54159861
3 changed files with 15 additions and 5 deletions
|
|
@ -318,11 +318,12 @@ class SecureCookieSessionInterface(SessionInterface):
|
|||
if not app.secret_key:
|
||||
return None
|
||||
|
||||
keys: list[str | bytes] = [app.secret_key]
|
||||
keys: list[str | bytes] = []
|
||||
|
||||
if fallbacks := app.config["SECRET_KEY_FALLBACKS"]:
|
||||
keys.extend(fallbacks)
|
||||
|
||||
keys.append(app.secret_key) # itsdangerous expects current key at top
|
||||
return URLSafeTimedSerializer(
|
||||
keys, # type: ignore[arg-type]
|
||||
salt=self.salt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue