@workos/authkit-session 0.5.3 → 0.6.0
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.
- package/dist/core/pkce/eviction.d.ts +53 -0
- package/dist/core/pkce/eviction.d.ts.map +1 -0
- package/dist/core/pkce/eviction.js +65 -0
- package/dist/core/pkce/eviction.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/service/AuthService.d.ts +23 -0
- package/dist/service/AuthService.d.ts.map +1 -1
- package/dist/service/AuthService.js +27 -2
- package/dist/service/AuthService.js.map +1 -1
- package/package.json +2 -2
- package/src/core/pkce/eviction.spec.ts +91 -0
- package/src/core/pkce/eviction.ts +77 -0
- package/src/index.ts +5 -0
- package/src/service/AuthService.spec.ts +47 -0
- package/src/service/AuthService.ts +33 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default ceiling on simultaneous pending PKCE verifier cookies before
|
|
3
|
+
* eviction kicks in. Mirrors `authkit-nextjs`'s `MAX_PKCE_COOKIES`.
|
|
4
|
+
*
|
|
5
|
+
* A handful of concurrent flows is normal — e.g. several tabs each
|
|
6
|
+
* mid-sign-in, each holding its own verifier. Eviction only triggers
|
|
7
|
+
* once accumulation risks an oversized `Cookie` request header
|
|
8
|
+
* (HTTP 431), which happens when an integration generates authorization
|
|
9
|
+
* URLs it never navigates to (prefetching `getSignInUrl()` in a loader).
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_MAX_PENDING_PKCE_COOKIES = 5;
|
|
12
|
+
/**
|
|
13
|
+
* True when `name` is a PKCE verifier cookie — either the per-flow hashed
|
|
14
|
+
* name (`wos-auth-verifier-<hash>`) or the legacy unsuffixed name.
|
|
15
|
+
*
|
|
16
|
+
* The hyphen boundary is required so a lookalike like
|
|
17
|
+
* `wos-auth-verifierXYZ` is NOT treated as a verifier.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isPKCEVerifierCookieName(name: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Decide which stale PKCE verifier cookies to evict on the request that
|
|
22
|
+
* mints `keep`.
|
|
23
|
+
*
|
|
24
|
+
* The per-flow cookie naming (each `getSignInUrl()`/`getSignUpUrl()` call
|
|
25
|
+
* derives a unique name from its sealed state) means cookies never
|
|
26
|
+
* overwrite — they accumulate until their 10-minute TTL. Generating URLs
|
|
27
|
+
* without navigating to them (e.g. prefetching in a loader) can pile up
|
|
28
|
+
* enough verifier cookies to exceed the server's request-header limit and
|
|
29
|
+
* surface as HTTP 431.
|
|
30
|
+
*
|
|
31
|
+
* Policy (matches `authkit-nextjs`): tolerate up to `max` simultaneous
|
|
32
|
+
* verifier cookies. Once the cookie being created this request would push
|
|
33
|
+
* the total past `max`, evict *every* other verifier — keeping only the
|
|
34
|
+
* one just minted. Because cookie names are content hashes with no
|
|
35
|
+
* embedded ordering, "keep the newest N" is not expressible; all-but-newest
|
|
36
|
+
* is the only well-defined bounded policy, and it mirrors the browser's own
|
|
37
|
+
* drop-oldest behavior at the cookie-jar limit.
|
|
38
|
+
*
|
|
39
|
+
* Pure and I/O-free: callers supply the incoming cookie names and emit the
|
|
40
|
+
* delete `Set-Cookie` headers for the returned names themselves.
|
|
41
|
+
*
|
|
42
|
+
* @param cookieNames - Names of all cookies on the incoming request.
|
|
43
|
+
* @param keep - Name of the verifier cookie being written this request;
|
|
44
|
+
* never included in the result.
|
|
45
|
+
* @param max - Maximum simultaneous verifier cookies tolerated before
|
|
46
|
+
* eviction. Defaults to {@link DEFAULT_MAX_PENDING_PKCE_COOKIES}.
|
|
47
|
+
* @returns Verifier cookie names to delete. Empty when within budget.
|
|
48
|
+
*/
|
|
49
|
+
export declare function selectStalePKCEVerifierCookieNames(cookieNames: Iterable<string>, { keep, max, }: {
|
|
50
|
+
keep: string;
|
|
51
|
+
max?: number;
|
|
52
|
+
}): string[];
|
|
53
|
+
//# sourceMappingURL=eviction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eviction.d.ts","sourceRoot":"","sources":["../../../src/core/pkce/eviction.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC7B,EACE,IAAI,EACJ,GAAsC,GACvC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAChC,MAAM,EAAE,CAcV"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { PKCE_COOKIE_PREFIX } from './cookieName.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default ceiling on simultaneous pending PKCE verifier cookies before
|
|
4
|
+
* eviction kicks in. Mirrors `authkit-nextjs`'s `MAX_PKCE_COOKIES`.
|
|
5
|
+
*
|
|
6
|
+
* A handful of concurrent flows is normal — e.g. several tabs each
|
|
7
|
+
* mid-sign-in, each holding its own verifier. Eviction only triggers
|
|
8
|
+
* once accumulation risks an oversized `Cookie` request header
|
|
9
|
+
* (HTTP 431), which happens when an integration generates authorization
|
|
10
|
+
* URLs it never navigates to (prefetching `getSignInUrl()` in a loader).
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_MAX_PENDING_PKCE_COOKIES = 5;
|
|
13
|
+
/**
|
|
14
|
+
* True when `name` is a PKCE verifier cookie — either the per-flow hashed
|
|
15
|
+
* name (`wos-auth-verifier-<hash>`) or the legacy unsuffixed name.
|
|
16
|
+
*
|
|
17
|
+
* The hyphen boundary is required so a lookalike like
|
|
18
|
+
* `wos-auth-verifierXYZ` is NOT treated as a verifier.
|
|
19
|
+
*/
|
|
20
|
+
export function isPKCEVerifierCookieName(name) {
|
|
21
|
+
return (name === PKCE_COOKIE_PREFIX || name.startsWith(`${PKCE_COOKIE_PREFIX}-`));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Decide which stale PKCE verifier cookies to evict on the request that
|
|
25
|
+
* mints `keep`.
|
|
26
|
+
*
|
|
27
|
+
* The per-flow cookie naming (each `getSignInUrl()`/`getSignUpUrl()` call
|
|
28
|
+
* derives a unique name from its sealed state) means cookies never
|
|
29
|
+
* overwrite — they accumulate until their 10-minute TTL. Generating URLs
|
|
30
|
+
* without navigating to them (e.g. prefetching in a loader) can pile up
|
|
31
|
+
* enough verifier cookies to exceed the server's request-header limit and
|
|
32
|
+
* surface as HTTP 431.
|
|
33
|
+
*
|
|
34
|
+
* Policy (matches `authkit-nextjs`): tolerate up to `max` simultaneous
|
|
35
|
+
* verifier cookies. Once the cookie being created this request would push
|
|
36
|
+
* the total past `max`, evict *every* other verifier — keeping only the
|
|
37
|
+
* one just minted. Because cookie names are content hashes with no
|
|
38
|
+
* embedded ordering, "keep the newest N" is not expressible; all-but-newest
|
|
39
|
+
* is the only well-defined bounded policy, and it mirrors the browser's own
|
|
40
|
+
* drop-oldest behavior at the cookie-jar limit.
|
|
41
|
+
*
|
|
42
|
+
* Pure and I/O-free: callers supply the incoming cookie names and emit the
|
|
43
|
+
* delete `Set-Cookie` headers for the returned names themselves.
|
|
44
|
+
*
|
|
45
|
+
* @param cookieNames - Names of all cookies on the incoming request.
|
|
46
|
+
* @param keep - Name of the verifier cookie being written this request;
|
|
47
|
+
* never included in the result.
|
|
48
|
+
* @param max - Maximum simultaneous verifier cookies tolerated before
|
|
49
|
+
* eviction. Defaults to {@link DEFAULT_MAX_PENDING_PKCE_COOKIES}.
|
|
50
|
+
* @returns Verifier cookie names to delete. Empty when within budget.
|
|
51
|
+
*/
|
|
52
|
+
export function selectStalePKCEVerifierCookieNames(cookieNames, { keep, max = DEFAULT_MAX_PENDING_PKCE_COOKIES, }) {
|
|
53
|
+
const others = new Set();
|
|
54
|
+
for (const name of cookieNames) {
|
|
55
|
+
if (name !== keep && isPKCEVerifierCookieName(name)) {
|
|
56
|
+
others.add(name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// +1 accounts for `keep`, which may not be on the incoming request yet.
|
|
60
|
+
if (others.size + 1 <= max) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return [...others];
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=eviction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eviction.js","sourceRoot":"","sources":["../../../src/core/pkce/eviction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,CACL,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,CAAC,CACzE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,kCAAkC,CAChD,WAA6B,EAC7B,EACE,IAAI,EACJ,GAAG,GAAG,gCAAgC,GACP;IAEjC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,IAAI,IAAI,KAAK,IAAI,IAAI,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,wEAAwE;IACxE,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { AuthKitCore } from './core/AuthKitCore.js';
|
|
|
25
25
|
export { AuthOperations } from './operations/AuthOperations.js';
|
|
26
26
|
export { CookieSessionStorage } from './core/session/CookieSessionStorage.js';
|
|
27
27
|
export { PKCE_COOKIE_PREFIX, getPKCECookieNameForState, } from './core/pkce/cookieName.js';
|
|
28
|
+
export { DEFAULT_MAX_PENDING_PKCE_COOKIES, isPKCEVerifierCookieName, selectStalePKCEVerifierCookieNames, } from './core/pkce/eviction.js';
|
|
28
29
|
export { default as sessionEncryption } from './core/encryption/ironWebcryptoEncryption.js';
|
|
29
30
|
export { configure, getConfig, getConfigurationProvider, validateConfig, } from './core/config.js';
|
|
30
31
|
export { ConfigurationProvider } from './core/config/ConfigurationProvider.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAK9E,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAK9E,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,kCAAkC,GACnC,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAK5F,OAAO,EACL,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAK/E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKpD,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAK1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,YAAY,EACV,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,sBAAsB,GACvB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ export { CookieSessionStorage } from './core/session/CookieSessionStorage.js';
|
|
|
37
37
|
// PKCE Helpers
|
|
38
38
|
// ============================================
|
|
39
39
|
export { PKCE_COOKIE_PREFIX, getPKCECookieNameForState, } from './core/pkce/cookieName.js';
|
|
40
|
+
export { DEFAULT_MAX_PENDING_PKCE_COOKIES, isPKCEVerifierCookieName, selectStalePKCEVerifierCookieNames, } from './core/pkce/eviction.js';
|
|
40
41
|
// ============================================
|
|
41
42
|
// Encryption Fallback
|
|
42
43
|
// ============================================
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,+CAA+C;AAC/C,aAAa;AACb,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,+CAA+C;AAC/C,6BAA6B;AAC7B,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,+CAA+C;AAC/C,kBAAkB;AAClB,+CAA+C;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,+CAA+C;AAC/C,eAAe;AACf,+CAA+C;AAC/C,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,+CAA+C;AAC/C,aAAa;AACb,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,+CAA+C;AAC/C,6BAA6B;AAC7B,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,+CAA+C;AAC/C,kBAAkB;AAClB,+CAA+C;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,+CAA+C;AAC/C,eAAe;AACf,+CAA+C;AAC/C,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,kCAAkC,GACnC,MAAM,yBAAyB,CAAC;AAEjC,+CAA+C;AAC/C,sBAAsB;AACtB,+CAA+C;AAC/C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAE5F,+CAA+C;AAC/C,gBAAgB;AAChB,+CAA+C;AAC/C,OAAO,EACL,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,+CAA+C;AAC/C,iBAAiB;AACjB,+CAA+C;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,+CAA+C;AAC/C,SAAS;AACT,+CAA+C;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,+CAA+C;AAC/C,eAAe;AACf,+CAA+C;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
|
|
@@ -136,6 +136,29 @@ export declare class AuthService<TRequest, TResponse> {
|
|
|
136
136
|
response?: TResponse;
|
|
137
137
|
headers?: HeadersBag;
|
|
138
138
|
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Emit a `Set-Cookie` header that clears a PKCE verifier cookie by its
|
|
141
|
+
* explicit name.
|
|
142
|
+
*
|
|
143
|
+
* Unlike {@link clearPendingVerifier}, this does not derive the name from
|
|
144
|
+
* a sealed `state` — it takes the cookie name directly. Use it to evict
|
|
145
|
+
* stale verifier cookies discovered by enumerating the request's cookies
|
|
146
|
+
* (e.g. via {@link selectStalePKCEVerifierCookieNames}), where the
|
|
147
|
+
* originating `state` is unknown and unrecoverable from the hashed name.
|
|
148
|
+
*
|
|
149
|
+
* The delete is computed with the same (name, path, domain) tuple the
|
|
150
|
+
* browser uses to match a cookie for replacement, so it clears the
|
|
151
|
+
* target regardless of the `redirectUri` the flow was created with. Pass
|
|
152
|
+
* `options.redirectUri` only when you need the `secure` attribute to match
|
|
153
|
+
* a per-request override.
|
|
154
|
+
*/
|
|
155
|
+
clearPendingVerifierByName(response: TResponse | undefined, options: {
|
|
156
|
+
cookieName: string;
|
|
157
|
+
redirectUri?: string;
|
|
158
|
+
}): Promise<{
|
|
159
|
+
response?: TResponse;
|
|
160
|
+
headers?: HeadersBag;
|
|
161
|
+
}>;
|
|
139
162
|
/**
|
|
140
163
|
* Get the WorkOS client instance.
|
|
141
164
|
* Useful for direct API calls not covered by AuthKit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthService.d.ts","sourceRoot":"","sources":["../../src/service/AuthService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthService.d.ts","sourceRoot":"","sources":["../../src/service/AuthService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAK7D,OAAO,KAAK,EACV,UAAU,EACV,yBAAyB,EACzB,YAAY,EACZ,0BAA0B,EAC1B,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,0BAA0B,CAAC;AAoClC;;;;;;;;;;;;;;GAcG;AACH,qBAAa,WAAW,CAAC,QAAQ,EAAE,SAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,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jB,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B;;;;;;;IAwEH;;;;;;;;;;;;OAYG;YACW,uBAAuB;CAiBtC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthKitCore } from '../core/AuthKitCore.js';
|
|
2
2
|
import { getPKCECookieNameForState } from '../core/pkce/cookieName.js';
|
|
3
3
|
import { getPKCECookieOptions } from '../core/pkce/cookieOptions.js';
|
|
4
|
+
import { isPKCEVerifierCookieName } from '../core/pkce/eviction.js';
|
|
4
5
|
import { AuthOperations } from '../operations/AuthOperations.js';
|
|
5
6
|
import { sanitizeReturnPathname } from '../utils.js';
|
|
6
7
|
/**
|
|
@@ -208,8 +209,32 @@ export class AuthService {
|
|
|
208
209
|
* computed attributes (notably `secure`) match the original set.
|
|
209
210
|
*/
|
|
210
211
|
async clearPendingVerifier(response, options) {
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
return this.clearPendingVerifierByName(response, {
|
|
213
|
+
cookieName: getPKCECookieNameForState(options.state),
|
|
214
|
+
redirectUri: options.redirectUri,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Emit a `Set-Cookie` header that clears a PKCE verifier cookie by its
|
|
219
|
+
* explicit name.
|
|
220
|
+
*
|
|
221
|
+
* Unlike {@link clearPendingVerifier}, this does not derive the name from
|
|
222
|
+
* a sealed `state` — it takes the cookie name directly. Use it to evict
|
|
223
|
+
* stale verifier cookies discovered by enumerating the request's cookies
|
|
224
|
+
* (e.g. via {@link selectStalePKCEVerifierCookieNames}), where the
|
|
225
|
+
* originating `state` is unknown and unrecoverable from the hashed name.
|
|
226
|
+
*
|
|
227
|
+
* The delete is computed with the same (name, path, domain) tuple the
|
|
228
|
+
* browser uses to match a cookie for replacement, so it clears the
|
|
229
|
+
* target regardless of the `redirectUri` the flow was created with. Pass
|
|
230
|
+
* `options.redirectUri` only when you need the `secure` attribute to match
|
|
231
|
+
* a per-request override.
|
|
232
|
+
*/
|
|
233
|
+
async clearPendingVerifierByName(response, options) {
|
|
234
|
+
if (!isPKCEVerifierCookieName(options.cookieName)) {
|
|
235
|
+
throw new Error(`Refusing to clear non-PKCE cookie "${options.cookieName}"`);
|
|
236
|
+
}
|
|
237
|
+
return this.storage.clearCookie(response, options.cookieName, getPKCECookieOptions(this.config, options.redirectUri));
|
|
213
238
|
}
|
|
214
239
|
/**
|
|
215
240
|
* Get the WorkOS client instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../src/service/AuthService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAWjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AACH,SAAS,eAAe,CACtB,CAAyB,EACzB,CAAyB;IAEzB,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACjB,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACjB,MAAM,MAAM,GAAe,EAAE,GAAG,CAAC,EAAE,CAAC;IACpC,IAAI,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CACzC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,YAAY,CACtC,CAAC;IACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,YAAY,EAAE,CAAC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|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Framework-agnostic authentication library for WorkOS with pluggable storage adapters",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"vitest": "^4.0.17"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@workos-inc/node": "^8.0.0 || ^9.0.0"
|
|
41
|
+
"@workos-inc/node": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=20.0.0"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_MAX_PENDING_PKCE_COOKIES,
|
|
4
|
+
isPKCEVerifierCookieName,
|
|
5
|
+
selectStalePKCEVerifierCookieNames,
|
|
6
|
+
} from './eviction.js';
|
|
7
|
+
import { PKCE_COOKIE_PREFIX, getPKCECookieNameForState } from './cookieName.js';
|
|
8
|
+
|
|
9
|
+
const verifier = (state: string) => getPKCECookieNameForState(state);
|
|
10
|
+
|
|
11
|
+
describe('isPKCEVerifierCookieName', () => {
|
|
12
|
+
it('matches the per-flow hashed name', () => {
|
|
13
|
+
expect(isPKCEVerifierCookieName(verifier('abc'))).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('matches the legacy unsuffixed name', () => {
|
|
17
|
+
expect(isPKCEVerifierCookieName(PKCE_COOKIE_PREFIX)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('rejects unrelated cookies', () => {
|
|
21
|
+
expect(isPKCEVerifierCookieName('wos-session')).toBe(false);
|
|
22
|
+
expect(isPKCEVerifierCookieName('foo')).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('rejects names that share the prefix without the hyphen boundary', () => {
|
|
26
|
+
// Guards against `wos-auth-verifierEVIL` being treated as a verifier.
|
|
27
|
+
expect(isPKCEVerifierCookieName(`${PKCE_COOKIE_PREFIX}EVIL`)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('selectStalePKCEVerifierCookieNames', () => {
|
|
32
|
+
const keep = verifier('new-flow');
|
|
33
|
+
|
|
34
|
+
it('evicts nothing when the new cookie is the only verifier', () => {
|
|
35
|
+
expect(selectStalePKCEVerifierCookieNames([], { keep })).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('evicts nothing while total verifier count stays within the cap', () => {
|
|
39
|
+
// 4 existing + the new one = 5 = DEFAULT cap.
|
|
40
|
+
const existing = ['a', 'b', 'c', 'd'].map(verifier);
|
|
41
|
+
expect(selectStalePKCEVerifierCookieNames(existing, { keep })).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('evicts every other verifier once the new cookie tips it over the cap', () => {
|
|
45
|
+
// 5 existing + the new one = 6 > 5.
|
|
46
|
+
const existing = ['a', 'b', 'c', 'd', 'e'].map(verifier);
|
|
47
|
+
const stale = selectStalePKCEVerifierCookieNames(existing, { keep });
|
|
48
|
+
expect(new Set(stale)).toEqual(new Set(existing));
|
|
49
|
+
expect(stale).not.toContain(keep);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('never evicts the cookie being kept, even if it is already on the request', () => {
|
|
53
|
+
const existing = [...['a', 'b', 'c', 'd'].map(verifier), keep];
|
|
54
|
+
// existing verifiers other than keep = 4; +1 new (keep, already counted) → within cap.
|
|
55
|
+
expect(selectStalePKCEVerifierCookieNames(existing, { keep })).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('ignores non-verifier cookies when counting', () => {
|
|
59
|
+
const existing = [
|
|
60
|
+
'wos-session',
|
|
61
|
+
'theme',
|
|
62
|
+
...['a', 'b', 'c', 'd'].map(verifier),
|
|
63
|
+
];
|
|
64
|
+
expect(selectStalePKCEVerifierCookieNames(existing, { keep })).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('honors a custom max', () => {
|
|
68
|
+
const existing = ['a', 'b'].map(verifier);
|
|
69
|
+
// 2 existing + 1 new = 3 > max:2 → evict both existing.
|
|
70
|
+
const stale = selectStalePKCEVerifierCookieNames(existing, {
|
|
71
|
+
keep,
|
|
72
|
+
max: 2,
|
|
73
|
+
});
|
|
74
|
+
expect(new Set(stale)).toEqual(new Set(existing));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('evicts all others even when only slightly over the cap (partial over-cap)', () => {
|
|
78
|
+
// max=3, 3 existing + 1 new = 4 > 3 → evicts all 3 existing (not just the surplus).
|
|
79
|
+
const existing = ['a', 'b', 'c'].map(verifier);
|
|
80
|
+
const stale = selectStalePKCEVerifierCookieNames(existing, {
|
|
81
|
+
keep,
|
|
82
|
+
max: 3,
|
|
83
|
+
});
|
|
84
|
+
expect(new Set(stale)).toEqual(new Set(existing));
|
|
85
|
+
expect(stale).not.toContain(keep);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('exposes a sane default cap', () => {
|
|
89
|
+
expect(DEFAULT_MAX_PENDING_PKCE_COOKIES).toBe(5);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PKCE_COOKIE_PREFIX } from './cookieName.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default ceiling on simultaneous pending PKCE verifier cookies before
|
|
5
|
+
* eviction kicks in. Mirrors `authkit-nextjs`'s `MAX_PKCE_COOKIES`.
|
|
6
|
+
*
|
|
7
|
+
* A handful of concurrent flows is normal — e.g. several tabs each
|
|
8
|
+
* mid-sign-in, each holding its own verifier. Eviction only triggers
|
|
9
|
+
* once accumulation risks an oversized `Cookie` request header
|
|
10
|
+
* (HTTP 431), which happens when an integration generates authorization
|
|
11
|
+
* URLs it never navigates to (prefetching `getSignInUrl()` in a loader).
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_MAX_PENDING_PKCE_COOKIES = 5;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* True when `name` is a PKCE verifier cookie — either the per-flow hashed
|
|
17
|
+
* name (`wos-auth-verifier-<hash>`) or the legacy unsuffixed name.
|
|
18
|
+
*
|
|
19
|
+
* The hyphen boundary is required so a lookalike like
|
|
20
|
+
* `wos-auth-verifierXYZ` is NOT treated as a verifier.
|
|
21
|
+
*/
|
|
22
|
+
export function isPKCEVerifierCookieName(name: string): boolean {
|
|
23
|
+
return (
|
|
24
|
+
name === PKCE_COOKIE_PREFIX || name.startsWith(`${PKCE_COOKIE_PREFIX}-`)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Decide which stale PKCE verifier cookies to evict on the request that
|
|
30
|
+
* mints `keep`.
|
|
31
|
+
*
|
|
32
|
+
* The per-flow cookie naming (each `getSignInUrl()`/`getSignUpUrl()` call
|
|
33
|
+
* derives a unique name from its sealed state) means cookies never
|
|
34
|
+
* overwrite — they accumulate until their 10-minute TTL. Generating URLs
|
|
35
|
+
* without navigating to them (e.g. prefetching in a loader) can pile up
|
|
36
|
+
* enough verifier cookies to exceed the server's request-header limit and
|
|
37
|
+
* surface as HTTP 431.
|
|
38
|
+
*
|
|
39
|
+
* Policy (matches `authkit-nextjs`): tolerate up to `max` simultaneous
|
|
40
|
+
* verifier cookies. Once the cookie being created this request would push
|
|
41
|
+
* the total past `max`, evict *every* other verifier — keeping only the
|
|
42
|
+
* one just minted. Because cookie names are content hashes with no
|
|
43
|
+
* embedded ordering, "keep the newest N" is not expressible; all-but-newest
|
|
44
|
+
* is the only well-defined bounded policy, and it mirrors the browser's own
|
|
45
|
+
* drop-oldest behavior at the cookie-jar limit.
|
|
46
|
+
*
|
|
47
|
+
* Pure and I/O-free: callers supply the incoming cookie names and emit the
|
|
48
|
+
* delete `Set-Cookie` headers for the returned names themselves.
|
|
49
|
+
*
|
|
50
|
+
* @param cookieNames - Names of all cookies on the incoming request.
|
|
51
|
+
* @param keep - Name of the verifier cookie being written this request;
|
|
52
|
+
* never included in the result.
|
|
53
|
+
* @param max - Maximum simultaneous verifier cookies tolerated before
|
|
54
|
+
* eviction. Defaults to {@link DEFAULT_MAX_PENDING_PKCE_COOKIES}.
|
|
55
|
+
* @returns Verifier cookie names to delete. Empty when within budget.
|
|
56
|
+
*/
|
|
57
|
+
export function selectStalePKCEVerifierCookieNames(
|
|
58
|
+
cookieNames: Iterable<string>,
|
|
59
|
+
{
|
|
60
|
+
keep,
|
|
61
|
+
max = DEFAULT_MAX_PENDING_PKCE_COOKIES,
|
|
62
|
+
}: { keep: string; max?: number },
|
|
63
|
+
): string[] {
|
|
64
|
+
const others = new Set<string>();
|
|
65
|
+
for (const name of cookieNames) {
|
|
66
|
+
if (name !== keep && isPKCEVerifierCookieName(name)) {
|
|
67
|
+
others.add(name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// +1 accounts for `keep`, which may not be on the incoming request yet.
|
|
72
|
+
if (others.size + 1 <= max) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return [...others];
|
|
77
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -44,6 +44,11 @@ export {
|
|
|
44
44
|
PKCE_COOKIE_PREFIX,
|
|
45
45
|
getPKCECookieNameForState,
|
|
46
46
|
} from './core/pkce/cookieName.js';
|
|
47
|
+
export {
|
|
48
|
+
DEFAULT_MAX_PENDING_PKCE_COOKIES,
|
|
49
|
+
isPKCEVerifierCookieName,
|
|
50
|
+
selectStalePKCEVerifierCookieNames,
|
|
51
|
+
} from './core/pkce/eviction.js';
|
|
47
52
|
|
|
48
53
|
// ============================================
|
|
49
54
|
// Encryption Fallback
|
|
@@ -407,6 +407,53 @@ describe('AuthService', () => {
|
|
|
407
407
|
});
|
|
408
408
|
});
|
|
409
409
|
|
|
410
|
+
describe('clearPendingVerifierByName()', () => {
|
|
411
|
+
let realStorage: ReturnType<typeof makeStorage>;
|
|
412
|
+
let realService: InstanceType<typeof AuthService>;
|
|
413
|
+
|
|
414
|
+
beforeEach(() => {
|
|
415
|
+
realStorage = makeStorage();
|
|
416
|
+
realService = new AuthService(
|
|
417
|
+
mockConfig as any,
|
|
418
|
+
realStorage as any,
|
|
419
|
+
makeClient() as any,
|
|
420
|
+
sessionEncryption,
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it('clears the named cookie without needing the sealed state', async () => {
|
|
425
|
+
const staleName = 'wos-auth-verifier-deadbeef';
|
|
426
|
+
const result = await realService.clearPendingVerifierByName(undefined, {
|
|
427
|
+
cookieName: staleName,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(realStorage.lastClearOptions.get(staleName)?.path).toBe('/');
|
|
431
|
+
expect(result.headers?.['Set-Cookie']).toContain(`${staleName}=`);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('rejects non-PKCE cookie names', async () => {
|
|
435
|
+
await expect(
|
|
436
|
+
realService.clearPendingVerifierByName(undefined, {
|
|
437
|
+
cookieName: 'wos-session',
|
|
438
|
+
}),
|
|
439
|
+
).rejects.toThrow('Refusing to clear non-PKCE cookie "wos-session"');
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('is what clearPendingVerifier delegates to (same options)', async () => {
|
|
443
|
+
const { cookieName } = await realService.createSignIn(undefined);
|
|
444
|
+
const sealedState = realStorage.cookies.get(cookieName)!;
|
|
445
|
+
|
|
446
|
+
const clearCookieSpy = vi.spyOn(realStorage, 'clearCookie');
|
|
447
|
+
await realService.clearPendingVerifier(undefined, { state: sealedState });
|
|
448
|
+
|
|
449
|
+
expect(clearCookieSpy).toHaveBeenCalledWith(
|
|
450
|
+
undefined,
|
|
451
|
+
cookieName,
|
|
452
|
+
expect.any(Object),
|
|
453
|
+
);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
410
457
|
describe('getWorkOS()', () => {
|
|
411
458
|
it('returns WorkOS client', () => {
|
|
412
459
|
const result = service.getWorkOS();
|
|
@@ -3,6 +3,7 @@ import { AuthKitCore } from '../core/AuthKitCore.js';
|
|
|
3
3
|
import type { AuthKitConfig } from '../core/config/types.js';
|
|
4
4
|
import { getPKCECookieNameForState } from '../core/pkce/cookieName.js';
|
|
5
5
|
import { getPKCECookieOptions } from '../core/pkce/cookieOptions.js';
|
|
6
|
+
import { isPKCEVerifierCookieName } from '../core/pkce/eviction.js';
|
|
6
7
|
import { AuthOperations } from '../operations/AuthOperations.js';
|
|
7
8
|
import type {
|
|
8
9
|
AuthResult,
|
|
@@ -283,10 +284,40 @@ export class AuthService<TRequest, TResponse> {
|
|
|
283
284
|
response: TResponse | undefined,
|
|
284
285
|
options: { state: string; redirectUri?: string },
|
|
285
286
|
): Promise<{ response?: TResponse; headers?: HeadersBag }> {
|
|
286
|
-
|
|
287
|
+
return this.clearPendingVerifierByName(response, {
|
|
288
|
+
cookieName: getPKCECookieNameForState(options.state),
|
|
289
|
+
redirectUri: options.redirectUri,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Emit a `Set-Cookie` header that clears a PKCE verifier cookie by its
|
|
295
|
+
* explicit name.
|
|
296
|
+
*
|
|
297
|
+
* Unlike {@link clearPendingVerifier}, this does not derive the name from
|
|
298
|
+
* a sealed `state` — it takes the cookie name directly. Use it to evict
|
|
299
|
+
* stale verifier cookies discovered by enumerating the request's cookies
|
|
300
|
+
* (e.g. via {@link selectStalePKCEVerifierCookieNames}), where the
|
|
301
|
+
* originating `state` is unknown and unrecoverable from the hashed name.
|
|
302
|
+
*
|
|
303
|
+
* The delete is computed with the same (name, path, domain) tuple the
|
|
304
|
+
* browser uses to match a cookie for replacement, so it clears the
|
|
305
|
+
* target regardless of the `redirectUri` the flow was created with. Pass
|
|
306
|
+
* `options.redirectUri` only when you need the `secure` attribute to match
|
|
307
|
+
* a per-request override.
|
|
308
|
+
*/
|
|
309
|
+
async clearPendingVerifierByName(
|
|
310
|
+
response: TResponse | undefined,
|
|
311
|
+
options: { cookieName: string; redirectUri?: string },
|
|
312
|
+
): Promise<{ response?: TResponse; headers?: HeadersBag }> {
|
|
313
|
+
if (!isPKCEVerifierCookieName(options.cookieName)) {
|
|
314
|
+
throw new Error(
|
|
315
|
+
`Refusing to clear non-PKCE cookie "${options.cookieName}"`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
287
318
|
return this.storage.clearCookie(
|
|
288
319
|
response,
|
|
289
|
-
cookieName,
|
|
320
|
+
options.cookieName,
|
|
290
321
|
getPKCECookieOptions(this.config, options.redirectUri),
|
|
291
322
|
);
|
|
292
323
|
}
|