Skip to content

Commit b5593ca

Browse files
committed
Support secret key fallbacks
These allow for key rotation (multiple active keys allowed until the older is retired). The naming matches Flask.
1 parent 9417607 commit b5593ca

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/quart/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class Quart(App):
258258
"PROVIDE_AUTOMATIC_OPTIONS": True,
259259
"RESPONSE_TIMEOUT": 60, # Second
260260
"SECRET_KEY": None,
261+
"SECRET_KEY_FALLBACKS": None,
261262
"SEND_FILE_MAX_AGE_DEFAULT": timedelta(hours=12),
262263
"SERVER_NAME": None,
263264
"SESSION_COOKIE_DOMAIN": None,

src/quart/sessions.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ def get_signing_serializer(self, app: Quart) -> URLSafeTimedSerializer | None:
149149
if not app.secret_key:
150150
return None
151151

152+
keys: list[str | bytes] = [app.secret_key]
153+
154+
if fallbacks := app.config["SECRET_KEY_FALLBACKS"]:
155+
keys.extend(fallbacks)
156+
152157
options = {
153158
"key_derivation": self.key_derivation,
154159
"digest_method": self.digest_method,
155160
}
156161
return URLSafeTimedSerializer(
157-
app.secret_key,
162+
keys, # type: ignore[arg-type]
158163
salt=self.salt,
159164
serializer=self.serializer,
160165
signer_kwargs=options,

0 commit comments

Comments
 (0)