@workos/authkit-session 0.7.1 → 0.8.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/README.md +30 -5
- package/dist/core/client/workos.d.ts +16 -2
- package/dist/core/client/workos.d.ts.map +1 -1
- package/dist/core/client/workos.js +24 -16
- package/dist/core/client/workos.js.map +1 -1
- package/dist/core/config/ConfigurationProvider.d.ts +1 -0
- package/dist/core/config/ConfigurationProvider.d.ts.map +1 -1
- package/dist/core/config/ConfigurationProvider.js +9 -1
- package/dist/core/config/ConfigurationProvider.js.map +1 -1
- package/dist/core/config/types.d.ts +38 -7
- package/dist/core/config/types.d.ts.map +1 -1
- package/dist/service/AuthService.d.ts +5 -0
- package/dist/service/AuthService.d.ts.map +1 -1
- package/dist/service/AuthService.js +5 -0
- package/dist/service/AuthService.js.map +1 -1
- package/dist/utils.d.ts +3 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -5
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/core/client/workos.spec.ts +99 -0
- package/src/core/client/workos.ts +24 -20
- package/src/core/config/ConfigurationProvider.spec.ts +189 -2
- package/src/core/config/ConfigurationProvider.ts +10 -1
- package/src/core/config/types.ts +40 -8
- package/src/core/config.spec.ts +1 -1
- package/src/service/AuthService.spec.ts +30 -0
- package/src/service/AuthService.ts +5 -0
- package/src/service/publicClient.spec.ts +271 -0
- package/src/utils.spec.ts +25 -0
- package/src/utils.ts +10 -5
package/src/utils.spec.ts
CHANGED
|
@@ -17,6 +17,15 @@ describe('utils', () => {
|
|
|
17
17
|
['protocol-relative URL', '//evil.com/steal'],
|
|
18
18
|
['backslash smuggle', '/\\evil.com/path'],
|
|
19
19
|
['double-backslash', '\\\\evil.com/path'],
|
|
20
|
+
['opaque path with backslash', 'x:\\evil.com'],
|
|
21
|
+
['non-special scheme with slash-backslash', 'x:/\\evil.com'],
|
|
22
|
+
['opaque path with double-backslash', 'x:\\\\evil.com'],
|
|
23
|
+
['opaque path with backslash-slash', 'x:\\/evil.com'],
|
|
24
|
+
['opaque path targeting the throwaway host', 'x:\\placeholder.invalid'],
|
|
25
|
+
[
|
|
26
|
+
'opaque path with query and fragment',
|
|
27
|
+
'x:\\evil.com/path?next=/home#login',
|
|
28
|
+
],
|
|
20
29
|
['javascript: scheme', 'javascript:alert(1)'],
|
|
21
30
|
['data: scheme', 'data:text/html,<script>alert(1)</script>'],
|
|
22
31
|
['tab smuggling', '/\tevil.com'],
|
|
@@ -61,6 +70,22 @@ describe('utils', () => {
|
|
|
61
70
|
);
|
|
62
71
|
});
|
|
63
72
|
|
|
73
|
+
it('uses the safe fallback when the normalized input would leave the origin', () => {
|
|
74
|
+
expect(
|
|
75
|
+
sanitizeReturnPathname('x:\\evil.com', '/login?retry=1#form'),
|
|
76
|
+
).toBe('/login?retry=1#form');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('rejects opaque-path bypasses in the fallback too', () => {
|
|
80
|
+
expect(sanitizeReturnPathname(undefined, 'x:\\evil.com')).toBe('/');
|
|
81
|
+
expect(sanitizeReturnPathname(undefined, 'x:\\placeholder.invalid')).toBe(
|
|
82
|
+
'/',
|
|
83
|
+
);
|
|
84
|
+
expect(sanitizeReturnPathname('x:/\\evil.com', 'x:\\/evil.com')).toBe(
|
|
85
|
+
'/',
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
64
89
|
it('backstops to `/` when both input and fallback are unusable', () => {
|
|
65
90
|
expect(sanitizeReturnPathname(undefined, '')).toBe('/');
|
|
66
91
|
expect(sanitizeReturnPathname(null, null as unknown as string)).toBe('/');
|
package/src/utils.ts
CHANGED
|
@@ -47,9 +47,9 @@ export function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
|
47
47
|
* state) to a same-origin relative URL. The returned value always begins
|
|
48
48
|
* with exactly one `/`, safe to emit directly as a `Location` header.
|
|
49
49
|
*
|
|
50
|
-
* Parsing against a throwaway origin
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* Parsing against a throwaway origin strips smuggled hosts and schemes.
|
|
51
|
+
* Re-resolving the normalized output also catches opaque paths whose raw
|
|
52
|
+
* backslashes become an authority when interpreted as a relative URL
|
|
53
53
|
* (CWE-601). `fallback` is sanitized by the same pipeline so a hostile
|
|
54
54
|
* fallback can't reopen the hole.
|
|
55
55
|
*/
|
|
@@ -57,12 +57,17 @@ export function sanitizeReturnPathname(
|
|
|
57
57
|
input: unknown,
|
|
58
58
|
fallback: string = '/',
|
|
59
59
|
): string {
|
|
60
|
+
const base = 'https://placeholder.invalid';
|
|
60
61
|
for (const candidate of [input, fallback]) {
|
|
61
62
|
if (typeof candidate !== 'string' || candidate.length === 0) continue;
|
|
62
63
|
try {
|
|
63
|
-
const parsed = new URL(candidate,
|
|
64
|
+
const parsed = new URL(candidate, base);
|
|
64
65
|
const path = '/' + parsed.pathname.replace(/^\/+/, '');
|
|
65
|
-
|
|
66
|
+
const result = `${path}${parsed.search}${parsed.hash}`;
|
|
67
|
+
// Reject authority syntax even when it names the throwaway host itself.
|
|
68
|
+
if (!result.startsWith('/\\') && new URL(result, base).origin === base) {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
66
71
|
} catch {
|
|
67
72
|
// Unparseable; try the next candidate.
|
|
68
73
|
}
|