feat(auth0-express): support session secret rotation - #36
Merged
Conversation
Widen `sessionSecret` to `string | string[]`. The first secret encrypts new cookies; all secrets are tried, in order, when decrypting — letting you roll the secret without logging existing users out. A comma-separated `AUTH0_SESSION_SECRET` / `SECRET` env var is parsed into an array in the same order. The underlying @auth0/auth0-server-js stores already accept an array secret, so this is a type widening plus env parsing; the required-secret guard now also rejects an empty array.
cschetan77
reviewed
Aug 3, 2026
…itly A programmatically-passed sessionSecret string bypassed comma-separated parsing since the spread of `config` happened after the env-based parse. Mirrors the existing appBaseUrl re-parse.
…n type sessionSecret is a required string | string[] field, so assigning the helper's string | string[] | undefined return type failed to compile. Add an overload so a definite string input is typed to never return undefined.
cschetan77
approved these changes
Aug 3, 2026
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
Adds session secret rotation to
@auth0/auth0-express, so you can roll the session secret without logging existing users out.sessionSecretnow acceptsstring | string[]. The first secret encrypts new cookies; all secrets are tried, in order, when decrypting.AUTH0_SESSION_SECRET(or legacySECRET) is parsed into an array in the same order — matching howAPP_BASE_URLalready handles comma-separated values.Rotation flow
sessionSecret: [newSecret, oldSecret]— new cookies encrypt undernewSecret, existingoldSecretcookies still decrypt.oldSecret.Tests
config.spec.ts— explicit array, comma-separatedAUTH0_SESSION_SECRET, comma-separated legacySECRET, single value stays a string, trailing-comma collapse, empty-array throws.session-secret-rotation.spec.ts(new) — end-to-end viacreateServerClientInstance: a cookie encrypted under the old secret is still readable after rotating to[new, old], and becomes unreadable once the old secret is dropped.All 186 tests pass; lint, typecheck, and build are clean.
Docs
sessionSecretJSDoc intypes.tsdocuments rotation.