@auth0/auth0-express 1.0.0-beta.2 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +1 -0
  2. package/dist/app-base-url.d.ts.map +1 -1
  3. package/dist/app-base-url.js +5 -1
  4. package/dist/app-base-url.js.map +1 -1
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +4 -0
  7. package/dist/config.js.map +1 -1
  8. package/dist/handlers/callback-handler.d.ts.map +1 -1
  9. package/dist/handlers/callback-handler.js +12 -0
  10. package/dist/handlers/callback-handler.js.map +1 -1
  11. package/dist/handlers/login-handler.d.ts.map +1 -1
  12. package/dist/handlers/login-handler.js +19 -0
  13. package/dist/handlers/login-handler.js.map +1 -1
  14. package/dist/handlers/logout-handler.d.ts.map +1 -1
  15. package/dist/handlers/logout-handler.js +8 -1
  16. package/dist/handlers/logout-handler.js.map +1 -1
  17. package/dist/handlers/start-enterprise-login.d.ts +21 -0
  18. package/dist/handlers/start-enterprise-login.d.ts.map +1 -0
  19. package/dist/handlers/start-enterprise-login.js +26 -0
  20. package/dist/handlers/start-enterprise-login.js.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/middleware/require-auth.d.ts +4 -0
  26. package/dist/middleware/require-auth.d.ts.map +1 -1
  27. package/dist/middleware/require-auth.js +4 -0
  28. package/dist/middleware/require-auth.js.map +1 -1
  29. package/dist/migration/index.d.ts +5 -0
  30. package/dist/migration/index.d.ts.map +1 -0
  31. package/dist/migration/index.js +3 -0
  32. package/dist/migration/index.js.map +1 -0
  33. package/dist/store/express-oidc-hkdf.d.ts +2 -0
  34. package/dist/store/express-oidc-hkdf.d.ts.map +1 -0
  35. package/dist/store/express-oidc-hkdf.js +11 -0
  36. package/dist/store/express-oidc-hkdf.js.map +1 -0
  37. package/dist/store/legacy-compatible-stateful-state-store.d.ts +139 -0
  38. package/dist/store/legacy-compatible-stateful-state-store.d.ts.map +1 -0
  39. package/dist/store/legacy-compatible-stateful-state-store.js +234 -0
  40. package/dist/store/legacy-compatible-stateful-state-store.js.map +1 -0
  41. package/dist/store/legacy-compatible-stateless-state-store.d.ts +82 -0
  42. package/dist/store/legacy-compatible-stateless-state-store.d.ts.map +1 -0
  43. package/dist/store/legacy-compatible-stateless-state-store.js +135 -0
  44. package/dist/store/legacy-compatible-stateless-state-store.js.map +1 -0
  45. package/dist/store/legacy-session-transformer.d.ts +67 -0
  46. package/dist/store/legacy-session-transformer.d.ts.map +1 -0
  47. package/dist/store/legacy-session-transformer.js +118 -0
  48. package/dist/store/legacy-session-transformer.js.map +1 -0
  49. package/dist/types.d.ts +67 -2
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/utils.d.ts.map +1 -1
  52. package/dist/utils.js +50 -10
  53. package/dist/utils.js.map +1 -1
  54. package/package.json +14 -7
@@ -0,0 +1,234 @@
1
+ import { StatefulStateStore, } from '@auth0/auth0-server-js';
2
+ import { LegacySessionTransformer, warnIfAbsoluteDurationUnset } from './legacy-session-transformer.js';
3
+ import { deriveHkdfKey } from './express-oidc-hkdf.js';
4
+ /**
5
+ * A server-side (stateful) state store for zero-downtime migration from `express-openid-connect`
6
+ * to `@auth0/auth0-express`.
7
+ *
8
+ * Extends {@link StatefulStateStore} and transparently reads existing
9
+ * `express-openid-connect` sessions from Redis, MongoDB, or any other custom store,
10
+ * converting them to the `auth0-server-js` format so users do not need to re-authenticate
11
+ * during the migration.
12
+ *
13
+ * **How it works:** `express-openid-connect` wraps session data in a `{ header, data, cookie }`
14
+ * envelope and stores a plain or JWS-signed session ID in the cookie. `auth0-server-js` stores
15
+ * {@link StateData} directly and encrypts the session ID in the cookie. This store overrides
16
+ * `decrypt` so the base machinery resolves the session ID from either cookie format, then reads
17
+ * the store by that ID. On `get`, a legacy envelope is transformed into {@link StateData} and
18
+ * immediately written back to the same store key via `set`, upgrading the session in place on
19
+ * first read rather than waiting for the caller's next write. This is what makes backchannel
20
+ * logout (`deleteByLogoutToken`) work for a migrated session right away: the app's store
21
+ * typically needs to index sessions by `sid` to resolve a logout token, and that index is
22
+ * naturally populated by `set`. A login (`removeIfExists=true`) still deletes the old key and
23
+ * rotates to a fresh ID.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { MigrationStatefulStateStore } from '@auth0/auth0-express/migration';
28
+ *
29
+ * const store = new MigrationStatefulStateStore(
30
+ * {
31
+ * secret: process.env.SESSION_SECRET,
32
+ * store: redisStore,
33
+ * legacySecret: process.env.SESSION_SECRET, // the secret used by express-openid-connect
34
+ * legacyAudience: 'https://api.example.com',
35
+ * legacyScope: 'openid profile email',
36
+ * },
37
+ * new ExpressCookieHandler()
38
+ * );
39
+ * ```
40
+ */
41
+ export class MigrationStatefulStateStore extends StatefulStateStore {
42
+ #legacySecrets;
43
+ #requireSignedLegacyCookie;
44
+ #transformer;
45
+ constructor(options, cookieHandler) {
46
+ super({
47
+ ...options.sessionConfiguration,
48
+ secret: options.secret,
49
+ store: options.store,
50
+ }, cookieHandler);
51
+ // Fall back to the app's session secret(s) when no explicit legacy secret is given. Either
52
+ // may be an array (rotation), so normalize both to a flat string[] tried in order.
53
+ const legacySecret = options.legacySecret ?? options.secret;
54
+ this.#legacySecrets = Array.isArray(legacySecret) ? legacySecret : [legacySecret];
55
+ this.#requireSignedLegacyCookie = options.requireSignedLegacyCookie ?? false;
56
+ const legacyAudience = options.legacyAudience ?? 'default';
57
+ const legacyScope = options.legacyScope ?? 'openid profile email offline_access';
58
+ this.#transformer = new LegacySessionTransformer(legacyAudience, legacyScope);
59
+ warnIfAbsoluteDurationUnset(options.sessionConfiguration);
60
+ }
61
+ /**
62
+ * Overrides decrypt() so the base StatefulStateStore machinery can resolve a session ID
63
+ * from BOTH modern and legacy express-openid-connect cookies.
64
+ *
65
+ * The base `getSessionId()` calls `this.decrypt(identifier, cookieValue)` and reads `.id`
66
+ * from the result. A modern auth0-server-js cookie is a compact JWE (exactly 5 dot-separated
67
+ * segments); a legacy cookie is a plain session ID (no dots) or a JWS-signed `<id>.<sig>`
68
+ * (one dot). We route strictly by shape and never cross-resolve: feeding a modern JWE into the
69
+ * legacy resolver would return the raw ciphertext as a "session ID" and orphan the real session
70
+ * (e.g. when the base throws JWTExpired on an expired-but-valid modern cookie). Modern cookies
71
+ * are delegated entirely to `super.decrypt` (preserving the base's expiry/error semantics);
72
+ * legacy cookies are resolved to `{ id }` so read and write operate on the same store key —
73
+ * upgrading the session in place on the first write.
74
+ *
75
+ * Note: routing is by dot-count. A legacy session ID that itself contains dots (only possible
76
+ * with a custom express-openid-connect `genid`) whose signed form reaches exactly 5 segments
77
+ * would be routed to the modern path and fail to resolve, forcing a one-time re-login. The
78
+ * default `genid` (32 hex chars, no dots) is unaffected.
79
+ */
80
+ async decrypt(identifier, encryptedStateData) {
81
+ // Modern cookie: a compact JWE has exactly 5 dot-separated segments. Delegate to the base,
82
+ // preserving its decryption and expiry semantics. Never fall back to legacy resolution here —
83
+ // that would use the raw ciphertext as a store key.
84
+ if (encryptedStateData.split('.').length === 5) {
85
+ return super.decrypt(identifier, encryptedStateData);
86
+ }
87
+ // Legacy cookie: a plain session ID (no dots) or JWS-signed `<id>.<sig>` (one dot).
88
+ const sessionId = await this.#resolveLegacySessionId(identifier, encryptedStateData);
89
+ if (sessionId === undefined)
90
+ return undefined;
91
+ return { id: sessionId };
92
+ }
93
+ /**
94
+ * Overrides get() to transform legacy express-openid-connect envelopes into StateData, and
95
+ * eagerly upgrades the session in place by writing the transformed data back immediately.
96
+ *
97
+ * ID resolution (modern or legacy) is handled by the decrypt() override, so this only needs
98
+ * to detect whether the value the base read from the store is a legacy `{ header, data, cookie }`
99
+ * envelope and, if so, transform it. Modern StateData passes through unchanged.
100
+ *
101
+ * Without the eager write, a migrated session would only be upgraded on the caller's next
102
+ * `set()` (e.g. token refresh, claim update) — until then, backchannel logout could not resolve
103
+ * it, since the app's store commonly builds its `sid` index inside `set()`. Writing here trades
104
+ * one extra store write on the session's first read after migration for backchannel logout
105
+ * working immediately, rather than only after some unrelated future write. The write reuses the
106
+ * same store key (`removeIfExists: false`) via the public `set()`, so it goes through the same
107
+ * cookie/session-id resolution as any other write and is a no-op cost-wise for legacy sessions
108
+ * that were about to be written anyway. A second `get()` within the same request re-reads the
109
+ * now-modern payload and skips the transform/write, so this only happens once per session.
110
+ */
111
+ async get(identifier, options) {
112
+ const data = await super.get(identifier, options);
113
+ if (data && this.#isLegacyStorePayload(data)) {
114
+ const stateData = this.#transformLegacyStorePayload(data);
115
+ // When there is legacy state data found, we write-on-first-read to
116
+ // convert the legacy session data, to the session data used by this SDK.
117
+ if (stateData) {
118
+ await this.set(identifier, stateData, false, options);
119
+ }
120
+ return stateData;
121
+ }
122
+ return data;
123
+ }
124
+ /**
125
+ * Resolves a legacy session ID from a raw cookie value. If the value contains a dot,
126
+ * it may be JWS-signed — try to verify and extract the unsigned portion.
127
+ *
128
+ * With {@link MigrationStatefulStateStoreOptions.requireSignedLegacyCookie} enabled, only a
129
+ * valid JWS signature is accepted: an unsigned cookie or one whose signature does not verify
130
+ * resolves to `undefined` (no session). Otherwise (the default, matching express-openid-connect
131
+ * with `requireSignedSessionStoreCookie: false`) the raw value is used as the store key when it
132
+ * is unsigned or its signature cannot be verified.
133
+ */
134
+ async #resolveLegacySessionId(cookieName, rawCookieValue) {
135
+ if (rawCookieValue.includes('.')) {
136
+ const stripped = await this.#resolveSignedCookie(cookieName, rawCookieValue);
137
+ if (stripped !== undefined)
138
+ return stripped;
139
+ }
140
+ // Signature required but the cookie was unsigned or failed verification: reject it rather than
141
+ // trusting the raw value as the store key.
142
+ if (this.#requireSignedLegacyCookie)
143
+ return undefined;
144
+ return rawCookieValue;
145
+ }
146
+ /**
147
+ * Type guard to check if data is in express-openid-connect SessionStorePayload format
148
+ */
149
+ #isLegacyStorePayload(data) {
150
+ if (!data || typeof data !== 'object') {
151
+ return false;
152
+ }
153
+ const payload = data;
154
+ if (!('header' in payload) || !('data' in payload) || !('cookie' in payload)) {
155
+ return false;
156
+ }
157
+ if (typeof payload.header !== 'object' || payload.header === null) {
158
+ return false;
159
+ }
160
+ // The header timestamps are trusted downstream: `exp` gates expiry and `iat` becomes
161
+ // `createdAt`. Require them to be numbers so a malformed envelope with a non-numeric `exp`
162
+ // cannot slip past the `exp <= now` comparison (which would coerce and read as "not expired").
163
+ const header = payload.header;
164
+ return typeof header.iat === 'number' && typeof header.uat === 'number' && typeof header.exp === 'number';
165
+ }
166
+ /**
167
+ * Transforms express-openid-connect SessionStorePayload to auth0-server-js StateData format.
168
+ * Rejects expired sessions.
169
+ */
170
+ #transformLegacyStorePayload(payload) {
171
+ // Reject once exp has been reached, mirroring appSession's `exp > epoch()` assertion
172
+ // (i.e. invalid when `exp <= now`), not one second later.
173
+ if (payload.header.exp <= Math.floor(Date.now() / 1000)) {
174
+ return undefined;
175
+ }
176
+ // Enforce this SDK's absoluteDuration on read. The legacy envelope's own exp reflects the OLD
177
+ // deployment's window, so a session past `createdAt + absoluteDuration` (calculateMaxAge <= 0)
178
+ // must be treated as expired here rather than returned for this one request before the
179
+ // write-back drops the cookie.
180
+ if (this.calculateMaxAge(payload.header.iat) <= 0) {
181
+ return undefined;
182
+ }
183
+ const sessionData = this.#transformer.transformLegacySession(payload.data);
184
+ sessionData.internal.createdAt = payload.header.iat;
185
+ return sessionData;
186
+ }
187
+ /**
188
+ * Attempts to verify a JWS-signed cookie from express-openid-connect and return the
189
+ * unsigned session ID. Tries each legacy secret in order.
190
+ */
191
+ async #resolveSignedCookie(cookieName, cookieValue) {
192
+ for (const secret of this.#legacySecrets) {
193
+ const result = await this.#verifySignedCookie(cookieName, cookieValue, secret);
194
+ if (result !== undefined) {
195
+ return result;
196
+ }
197
+ }
198
+ return undefined;
199
+ }
200
+ async #deriveLegacySigningKey(secret) {
201
+ const keyBytes = await deriveHkdfKey(secret, 'JWS Cookie Signing');
202
+ return crypto.subtle.importKey('raw', keyBytes, { name: 'HMAC', hash: 'SHA-256' }, false, ['verify']);
203
+ }
204
+ async #verifySignedCookie(cookieName, cookieValue, secret) {
205
+ try {
206
+ const dotIndex = cookieValue.lastIndexOf('.');
207
+ if (dotIndex === -1)
208
+ return undefined;
209
+ const sessionId = cookieValue.substring(0, dotIndex);
210
+ const signatureB64 = cookieValue.substring(dotIndex + 1);
211
+ // The fixed JWS header used by express-openid-connect
212
+ const HEADER_B64 = 'eyJhbGciOiJIUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19';
213
+ const encoder = new TextEncoder();
214
+ const rawPayload = encoder.encode(`${cookieName}=${sessionId}`);
215
+ const headerBytes = encoder.encode(HEADER_B64 + '.');
216
+ const signingInput = new Uint8Array(headerBytes.length + rawPayload.length);
217
+ signingInput.set(headerBytes, 0);
218
+ signingInput.set(rawPayload, headerBytes.length);
219
+ const cryptoKey = await this.#deriveLegacySigningKey(secret);
220
+ // Decode the base64url signature
221
+ const sigBase64 = signatureB64.replace(/-/g, '+').replace(/_/g, '/');
222
+ const sigRaw = atob(sigBase64);
223
+ const sigBytes = new Uint8Array(sigRaw.length);
224
+ for (let i = 0; i < sigRaw.length; i++)
225
+ sigBytes[i] = sigRaw.charCodeAt(i);
226
+ const valid = await crypto.subtle.verify('HMAC', cryptoKey, sigBytes, signingInput);
227
+ return valid ? sessionId : undefined;
228
+ }
229
+ catch {
230
+ return undefined;
231
+ }
232
+ }
233
+ }
234
+ //# sourceMappingURL=legacy-compatible-stateful-state-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-compatible-stateful-state-store.js","sourceRoot":"","sources":["../../src/store/legacy-compatible-stateful-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAInB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAA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auth0/auth0-server-js';
2
+ import type { CookieHandler } from '@auth0/auth0-server-js';
3
+ /**
4
+ * Options for {@link MigrationStatelessStateStore}.
5
+ */
6
+ export interface MigrationStatelessStateStoreOptions {
7
+ /**
8
+ * The secret used by auth0-server-js for encryption.
9
+ *
10
+ * Provide an array to support secret rotation: the first secret encrypts new cookies, while
11
+ * all secrets are tried, in order, when decrypting.
12
+ */
13
+ secret: string | string[];
14
+ /**
15
+ * The secret(s) that were used by express-openid-connect for encryption.
16
+ * Supports key rotation: provide an array to try multiple secrets in order.
17
+ * If not provided, falls back to using the same secret as auth0-server-js.
18
+ */
19
+ legacySecret?: string | string[];
20
+ /**
21
+ * The audience to assign to transformed token sets from express-openid-connect sessions.
22
+ *
23
+ * Token sets are looked up by audience, so this must equal the `audience` your app requests
24
+ * (e.g. via `getAccessToken`) or the migrated access token will not be found. The default
25
+ * `'default'` only matches callers that request no audience.
26
+ *
27
+ * Default: 'default'
28
+ */
29
+ legacyAudience?: string;
30
+ /**
31
+ * The scope to assign to transformed token sets from express-openid-connect sessions.
32
+ * @default 'openid profile email offline_access'
33
+ */
34
+ legacyScope?: string;
35
+ /**
36
+ * Session configuration options
37
+ */
38
+ sessionConfiguration?: SessionConfiguration;
39
+ }
40
+ /**
41
+ * A cookie-based (stateless) state store for zero-downtime migration from `express-openid-connect`
42
+ * to `@auth0/auth0-express`.
43
+ *
44
+ * Extends {@link StatelessStateStore} and transparently decrypts existing
45
+ * `express-openid-connect` session cookies on first access, converting them to the
46
+ * `auth0-server-js` format so users do not need to re-authenticate during the migration.
47
+ *
48
+ * **How it works:** `express-openid-connect` encrypts session cookies with `A256GCM` (HKDF
49
+ * derived, info `"JWE CEK"`). `auth0-server-js` uses `A256CBC-HS512` with a different
50
+ * derivation. This store tries the modern decryption first; if that fails it falls back to
51
+ * the `express-openid-connect` decryption and transforms the result into {@link StateData}.
52
+ *
53
+ * Once the user's next request writes back the session, the cookie is re-encrypted in the
54
+ * modern format and this fallback path is no longer exercised for that user.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { MigrationStatelessStateStore } from '@auth0/auth0-express/migration';
59
+ *
60
+ * const store = new MigrationStatelessStateStore(
61
+ * {
62
+ * secret: process.env.SESSION_SECRET,
63
+ * legacySecret: process.env.SESSION_SECRET, // the secret used by express-openid-connect
64
+ * legacyAudience: 'https://api.example.com',
65
+ * legacyScope: 'openid profile email',
66
+ * },
67
+ * new ExpressCookieHandler()
68
+ * );
69
+ * ```
70
+ */
71
+ export declare class MigrationStatelessStateStore<TStoreOptions> extends StatelessStateStore<TStoreOptions> {
72
+ #private;
73
+ constructor(options: MigrationStatelessStateStoreOptions, cookieHandler: CookieHandler<TStoreOptions>);
74
+ /**
75
+ * Overrides the decrypt method to try modern decryption first, then fall back to legacy decryption.
76
+ *
77
+ * The base class decrypt throws on decryption failure. We catch that and attempt legacy
78
+ * express-openid-connect decryption. If both fail, we return undefined.
79
+ */
80
+ protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData | undefined>;
81
+ }
82
+ //# sourceMappingURL=legacy-compatible-stateless-state-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-compatible-stateless-state-store.d.ts","sourceRoot":"","sources":["../../src/store/legacy-compatible-stateless-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAO5D;;GAEG;AACH,MAAM,WAAW,mCAAmC;IAClD;;;;;OAKG;IACH,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE1B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEjC;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,4BAA4B,CAAC,aAAa,CAAE,SAAQ,mBAAmB,CAAC,aAAa,CAAC;;gBAIrF,OAAO,EAAE,mCAAmC,EAAE,aAAa,EAAE,aAAa,CAAC,aAAa,CAAC;IAqBrG;;;;;OAKG;cACsB,OAAO,CAAC,KAAK,EACpC,UAAU,EAAE,MAAM,EAClB,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAgF9B"}
@@ -0,0 +1,135 @@
1
+ import { StatelessStateStore } from '@auth0/auth0-server-js';
2
+ import { jwtDecrypt, errors } from 'jose';
3
+ import { LegacySessionTransformer, warnIfAbsoluteDurationUnset } from './legacy-session-transformer.js';
4
+ import { deriveHkdfKey } from './express-oidc-hkdf.js';
5
+ /**
6
+ * A cookie-based (stateless) state store for zero-downtime migration from `express-openid-connect`
7
+ * to `@auth0/auth0-express`.
8
+ *
9
+ * Extends {@link StatelessStateStore} and transparently decrypts existing
10
+ * `express-openid-connect` session cookies on first access, converting them to the
11
+ * `auth0-server-js` format so users do not need to re-authenticate during the migration.
12
+ *
13
+ * **How it works:** `express-openid-connect` encrypts session cookies with `A256GCM` (HKDF
14
+ * derived, info `"JWE CEK"`). `auth0-server-js` uses `A256CBC-HS512` with a different
15
+ * derivation. This store tries the modern decryption first; if that fails it falls back to
16
+ * the `express-openid-connect` decryption and transforms the result into {@link StateData}.
17
+ *
18
+ * Once the user's next request writes back the session, the cookie is re-encrypted in the
19
+ * modern format and this fallback path is no longer exercised for that user.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { MigrationStatelessStateStore } from '@auth0/auth0-express/migration';
24
+ *
25
+ * const store = new MigrationStatelessStateStore(
26
+ * {
27
+ * secret: process.env.SESSION_SECRET,
28
+ * legacySecret: process.env.SESSION_SECRET, // the secret used by express-openid-connect
29
+ * legacyAudience: 'https://api.example.com',
30
+ * legacyScope: 'openid profile email',
31
+ * },
32
+ * new ExpressCookieHandler()
33
+ * );
34
+ * ```
35
+ */
36
+ export class MigrationStatelessStateStore extends StatelessStateStore {
37
+ #legacySecrets;
38
+ #transformer;
39
+ constructor(options, cookieHandler) {
40
+ super({
41
+ ...options.sessionConfiguration,
42
+ secret: options.secret,
43
+ }, cookieHandler);
44
+ // Fall back to the app's session secret(s) when no explicit legacy secret is given. Either
45
+ // may be an array (rotation), so normalize both to a flat string[] tried in order.
46
+ const legacySecret = options.legacySecret ?? options.secret;
47
+ this.#legacySecrets = Array.isArray(legacySecret) ? legacySecret : [legacySecret];
48
+ const legacyAudience = options.legacyAudience ?? 'default';
49
+ const legacyScope = options.legacyScope ?? 'openid profile email offline_access';
50
+ this.#transformer = new LegacySessionTransformer(legacyAudience, legacyScope);
51
+ warnIfAbsoluteDurationUnset(options.sessionConfiguration);
52
+ }
53
+ /**
54
+ * Overrides the decrypt method to try modern decryption first, then fall back to legacy decryption.
55
+ *
56
+ * The base class decrypt throws on decryption failure. We catch that and attempt legacy
57
+ * express-openid-connect decryption. If both fail, we return undefined.
58
+ */
59
+ async decrypt(identifier, encryptedStateData) {
60
+ try {
61
+ const modernResult = await super.decrypt(identifier, encryptedStateData);
62
+ if (modernResult !== undefined)
63
+ return modernResult;
64
+ }
65
+ catch {
66
+ // Modern decryption threw — fall through to legacy attempt.
67
+ }
68
+ const legacyResult = await this.#decryptLegacy(encryptedStateData);
69
+ if (!legacyResult)
70
+ return undefined;
71
+ const { session: legacyData, iat } = legacyResult;
72
+ const stateData = this.#transformer.transformLegacySession(legacyData);
73
+ if (iat !== undefined) {
74
+ stateData.internal.createdAt = iat;
75
+ // Enforce this SDK's absoluteDuration on read. A migrated cookie still carries
76
+ // express-openid-connect's own Max-Age/exp (the OLD deployment's window), so unlike a modern
77
+ // cookie the browser does not stop sending it at this SDK's cap and there is no modern `exp`
78
+ // to reject it. `calculateMaxAge(iat) <= 0` means the session is already past
79
+ // `createdAt + absoluteDuration`: treat it as expired and return no session rather than
80
+ // honoring it until the next write.
81
+ if (this.calculateMaxAge(iat) <= 0) {
82
+ return undefined;
83
+ }
84
+ }
85
+ return stateData;
86
+ }
87
+ /**
88
+ * Decrypts data using express-openid-connect's encryption method (A256GCM with HKDF).
89
+ * Tries each secret in order; the first successful decryption wins (key rotation support).
90
+ * Returns the session payload and the header `iat`, or undefined if all secrets fail.
91
+ */
92
+ async #decryptLegacy(encryptedData) {
93
+ for (const secret of this.#legacySecrets) {
94
+ try {
95
+ const key = await this.#deriveLegacyKey(secret);
96
+ const { payload, protectedHeader } = await jwtDecrypt(encryptedData, key, {
97
+ contentEncryptionAlgorithms: ['A256GCM'],
98
+ keyManagementAlgorithms: ['dir'],
99
+ });
100
+ const header = protectedHeader;
101
+ // Check header-level exp (express-openid-connect stores exp in the JWE header, not the
102
+ // payload). A genuine express-openid-connect cookie always carries a numeric exp; reject a
103
+ // cookie that lacks one, rather than accepting an exp-less cookie indefinitely. Reject once
104
+ // exp has been reached, mirroring appSession's `exp > epoch()` assertion (i.e. invalid when
105
+ // `exp <= now`), not one second later.
106
+ const headerExp = header.exp;
107
+ if (typeof headerExp !== 'number' || headerExp <= Math.floor(Date.now() / 1000)) {
108
+ return undefined;
109
+ }
110
+ const headerIat = header.iat;
111
+ return {
112
+ session: payload,
113
+ iat: typeof headerIat === 'number' ? headerIat : undefined,
114
+ };
115
+ }
116
+ catch (err) {
117
+ // Swallow any JOSE-level failure and try the next secret / fall through to "no session".
118
+ // Besides the expected JWEDecryptionFailed / JWEInvalid (wrong key or malformed JWE), a
119
+ // modern auth0-server-js cookie (A256CBC-HS512) fed into this A256GCM-only path throws
120
+ // JOSEAlgNotAllowed. All jose errors extend JOSEError, so this fails soft to `undefined`
121
+ // ("logged out"), matching the base store, while genuine programming errors (e.g.
122
+ // TypeError from a broken Web Crypto) are not JOSEError and still propagate.
123
+ if (!(err instanceof errors.JOSEError)) {
124
+ throw err;
125
+ }
126
+ continue;
127
+ }
128
+ }
129
+ return undefined;
130
+ }
131
+ async #deriveLegacyKey(secret) {
132
+ return deriveHkdfKey(secret, 'JWE CEK');
133
+ }
134
+ }
135
+ //# sourceMappingURL=legacy-compatible-stateless-state-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-compatible-stateless-state-store.js","sourceRoot":"","sources":["../../src/store/legacy-compatible-stateless-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA4CvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,4BAA4C,SAAQ,mBAAkC;IACxF,cAAc,CAAW;IACzB,YAAY,CAA2B;IAEhD,YAAY,OAA4C,EAAE,aAA2C;QACnG,KAAK,CACH;YACE,GAAG,OAAO,CAAC,oBAAoB;YAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,EACD,aAAa,CACd,CAAC;QAEF,2FAA2F;QAC3F,mFAAmF;QACnF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;QAC5D,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAElF,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,SAAS,CAAC;QAC3D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,qCAAqC,CAAC;QACjF,IAAI,CAAC,YAAY,GAAG,IAAI,wBAAwB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAE9E,2BAA2B,CAAC,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EAAE,GAAG,EAAE;oBACxE,2BAA2B,EAAE,CAAC,SAAS,CAAC;oBACxC,uBAAuB,EAAE,CAAC,KAAK,CAAC;iBACjC,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,eAAgE,CAAC;gBAEhF,uFAAuF;gBACvF,2FAA2F;gBAC3F,4FAA4F;gBAC5F,4FAA4F;gBAC5F,uCAAuC;gBACvC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;gBAC7B,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;oBAChF,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;gBAC7B,OAAO;oBACL,OAAO,EAAE,OAAsC;oBAC/C,GAAG,EAAE,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;iBAC3D,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,yFAAyF;gBACzF,wFAAwF;gBACxF,uFAAuF;gBACvF,yFAAyF;gBACzF,kFAAkF;gBAClF,6EAA6E;gBAC7E,IAAI,CAAC,CAAC,GAAG,YAAY,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;oBACvC,MAAM,GAAG,CAAC;gBACZ,CAAC;gBACD,SAAS;YACX,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAc;QACnC,OAAO,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,67 @@
1
+ import type { UserClaims, StateData } from '@auth0/auth0-server-js';
2
+ /**
3
+ * Legacy session format from express-openid-connect
4
+ */
5
+ export interface ExpressOpenidConnectSession {
6
+ id_token?: string;
7
+ access_token?: string;
8
+ refresh_token?: string;
9
+ token_type?: string;
10
+ expires_at?: number | string;
11
+ [key: string]: unknown;
12
+ }
13
+ /**
14
+ * Session store payload structure from express-openid-connect
15
+ */
16
+ export interface ExpressOpenidConnectStorePayload {
17
+ header: {
18
+ iat: number;
19
+ uat: number;
20
+ exp: number;
21
+ };
22
+ data: ExpressOpenidConnectSession;
23
+ cookie: {
24
+ expires: number;
25
+ maxAge: number;
26
+ };
27
+ }
28
+ /**
29
+ * Shared utility for transforming legacy express-openid-connect sessions to auth0-server-js StateData format.
30
+ */
31
+ export declare class LegacySessionTransformer {
32
+ #private;
33
+ constructor(audience: string, scope: string);
34
+ /**
35
+ * Transforms express-openid-connect session format to auth0-server-js StateData format
36
+ */
37
+ transformLegacySession(legacy: ExpressOpenidConnectSession): StateData;
38
+ /**
39
+ * Decodes a JWT token without verification to extract claims.
40
+ * This is safe for transformations since the token was already encrypted
41
+ * in the session and will be re-encrypted.
42
+ */
43
+ decodeJWT(token: string): UserClaims | undefined;
44
+ }
45
+ /**
46
+ * Emits a one-time startup warning when a migration store is constructed without an explicit
47
+ * `sessionConfiguration.absoluteDuration`. A migrated session keeps its original
48
+ * express-openid-connect creation time, and this SDK expires a session at
49
+ * `createdAt + absoluteDuration`. This SDK defaults `absoluteDuration` to 3 days while
50
+ * express-openid-connect defaults it to 7 — so relying on the default *can* cut short a
51
+ * carried-over session already older than 3 days. Warning once at construction (rather than per
52
+ * read) surfaces the potential misconfiguration before any user is affected, without log spam or
53
+ * per-session bookkeeping.
54
+ *
55
+ * This is a heuristic for the most common mistake ("forgot to raise it"), not a precise check: it
56
+ * only knows whether the value was *set*, not whether it is large enough for the sessions being
57
+ * migrated. It cannot see the old deployment's `absoluteDuration`, so it may warn when the old
58
+ * value was actually lower (the default is then fine), and it stays silent when an explicit value
59
+ * is still too low. It only fires when the value is left unset — an app that chose a value made a
60
+ * deliberate decision and is not warned.
61
+ *
62
+ * @param sessionConfiguration The store's session configuration, if any.
63
+ */
64
+ export declare function warnIfAbsoluteDurationUnset(sessionConfiguration?: {
65
+ absoluteDuration?: number;
66
+ }): void;
67
+ //# sourceMappingURL=legacy-session-transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-session-transformer.d.ts","sourceRoot":"","sources":["../../src/store/legacy-session-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,2BAA2B,CAAC;IAClC,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,wBAAwB;;gBAIvB,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAK3C;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,2BAA2B,GAAG,SAAS;IA2DtE;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;CAejD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,2BAA2B,CAAC,oBAAoB,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAatG"}