@authfn/client 0.4.1 → 0.5.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/browser-handoff.d.ts +257 -0
- package/dist/browser-handoff.d.ts.map +1 -0
- package/dist/browser-handoff.js +923 -0
- package/dist/browser-handoff.js.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/http-client.d.ts +8 -0
- package/dist/http-client.d.ts.map +1 -1
- package/dist/http-client.js +329 -15
- package/dist/http-client.js.map +1 -1
- 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/region-id.d.ts +13 -0
- package/dist/region-id.d.ts.map +1 -0
- package/dist/region-id.js +21 -0
- package/dist/region-id.js.map +1 -0
- package/dist/secret-text.d.ts +25 -0
- package/dist/secret-text.d.ts.map +1 -0
- package/dist/secret-text.js +111 -0
- package/dist/secret-text.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The most characters a region id may have: the server stores it as a
|
|
3
|
+
* database key (`AUTHFN_DATABASE_KEY_MAX_LENGTH`).
|
|
4
|
+
*/
|
|
5
|
+
export const REGION_ID_MAX_LENGTH = 255;
|
|
6
|
+
// eslint-disable-next-line no-control-regex
|
|
7
|
+
const CONTROL_CHARACTER = /[\u0000-\u001f\u007f-\u009f]/;
|
|
8
|
+
/**
|
|
9
|
+
* Whether `value` is a region id AuthFn accepts. The server treats region
|
|
10
|
+
* ids as opaque, so this checks only what every id satisfies: a non-empty
|
|
11
|
+
* string of at most 255 characters with no control characters and no
|
|
12
|
+
* leading or trailing whitespace (`aws:eu-west-1` is one).
|
|
13
|
+
*/
|
|
14
|
+
export function isRegionId(value) {
|
|
15
|
+
return (typeof value === 'string'
|
|
16
|
+
&& value.length > 0
|
|
17
|
+
&& Array.from(value).length <= REGION_ID_MAX_LENGTH
|
|
18
|
+
&& value.trim() === value
|
|
19
|
+
&& !CONTROL_CHARACTER.test(value));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=region-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"region-id.js","sourceRoot":"","sources":["../src/region-id.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,4CAA4C;AAC5C,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;WACtB,KAAK,CAAC,MAAM,GAAG,CAAC;WAChB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,IAAI,oBAAoB;WAChD,KAAK,CAAC,IAAI,EAAE,KAAK,KAAK;WACtB,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one check for whether text repeats a one-time secret (a handoff code or
|
|
3
|
+
* verifier), shared by the sensitive request path and the browser handoff.
|
|
4
|
+
*/
|
|
5
|
+
/** A reported value may not repeat this many consecutive characters of a secret. */
|
|
6
|
+
export declare const SECRET_WINDOW = 8;
|
|
7
|
+
/** A check a reported value must pass: a pattern it matches or a predicate. */
|
|
8
|
+
export type TextCheck = RegExp | ((value: string) => boolean);
|
|
9
|
+
/** `value` when it is a string that passes `check` and shares no text with `secrets`. */
|
|
10
|
+
export declare function safeText(value: unknown, check: TextCheck, secrets: readonly string[]): string | undefined;
|
|
11
|
+
/** `safeText`, except that a value equal to one of `PUBLIC_LABELS` passes `check` alone. */
|
|
12
|
+
export declare function safeLabel(value: unknown, check: TextCheck, secrets: readonly string[]): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `value` contains `secret`, or any run of `SECRET_WINDOW` of its
|
|
15
|
+
* characters, as written or percent-decoded up to `DECODE_PASSES` times.
|
|
16
|
+
*/
|
|
17
|
+
export declare function sharesText(value: string, secret: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether any string in `value`, keys included, at any depth, shares text
|
|
20
|
+
* with `secrets`. A value that cannot be walked counts as sharing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function repeatsSecret(value: unknown, secrets: readonly string[]): boolean;
|
|
23
|
+
/** Every non-empty string value in a JSON request body. */
|
|
24
|
+
export declare function collectBodyStrings(body: unknown, found?: string[]): string[];
|
|
25
|
+
//# sourceMappingURL=secret-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-text.d.ts","sourceRoot":"","sources":["../src/secret-text.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oFAAoF;AACpF,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAE9D,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAKzG;AAyBD,4FAA4F;AAC5F,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAI1G;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAYjE;AAqBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAiBjF;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE,CAWhF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one check for whether text repeats a one-time secret (a handoff code or
|
|
3
|
+
* verifier), shared by the sensitive request path and the browser handoff.
|
|
4
|
+
*/
|
|
5
|
+
/** A reported value may not repeat this many consecutive characters of a secret. */
|
|
6
|
+
export const SECRET_WINDOW = 8;
|
|
7
|
+
/** `value` when it is a string that passes `check` and shares no text with `secrets`. */
|
|
8
|
+
export function safeText(value, check, secrets) {
|
|
9
|
+
if (typeof value !== 'string' || !(typeof check === 'function' ? check(value) : check.test(value))) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return secrets.some((secret) => sharesText(value, secret)) ? undefined : value;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The client's own fixed public labels: the error codes it builds itself,
|
|
16
|
+
* the codes the social handoff exchange documents and the request fields that
|
|
17
|
+
* exchange names in a validation error. A value equal to one of them is that
|
|
18
|
+
* label, not a reflection of a secret.
|
|
19
|
+
*/
|
|
20
|
+
const PUBLIC_LABELS = new Set([
|
|
21
|
+
'AUTHFN_NETWORK_ERROR',
|
|
22
|
+
'AUTHFN_INTERNAL_ERROR',
|
|
23
|
+
'AUTHFN_REDIRECT_REQUIRES_NAVIGATION',
|
|
24
|
+
'AUTHFN_OAUTH_CALLBACK_FAILED',
|
|
25
|
+
'AUTHFN_ACCOUNT_ALREADY_EXISTS',
|
|
26
|
+
'AUTHFN_OAUTH_STATE_INVALID',
|
|
27
|
+
'AUTHFN_OAUTH_STATE_REPLAYED',
|
|
28
|
+
'AUTHFN_OAUTH_CALLBACK_INVALID',
|
|
29
|
+
'AUTHFN_REGION_MISMATCH',
|
|
30
|
+
'AUTHFN_RATE_LIMITED',
|
|
31
|
+
'AUTHFN_VALIDATION_ERROR',
|
|
32
|
+
'code',
|
|
33
|
+
'verifier',
|
|
34
|
+
'userId'
|
|
35
|
+
]);
|
|
36
|
+
/** `safeText`, except that a value equal to one of `PUBLIC_LABELS` passes `check` alone. */
|
|
37
|
+
export function safeLabel(value, check, secrets) {
|
|
38
|
+
return typeof value === 'string' && PUBLIC_LABELS.has(value)
|
|
39
|
+
? safeText(value, check, [])
|
|
40
|
+
: safeText(value, check, secrets);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether `value` contains `secret`, or any run of `SECRET_WINDOW` of its
|
|
44
|
+
* characters, as written or percent-decoded up to `DECODE_PASSES` times.
|
|
45
|
+
*/
|
|
46
|
+
export function sharesText(value, secret) {
|
|
47
|
+
const forms = decodedForms(value);
|
|
48
|
+
if (secret.length <= SECRET_WINDOW) {
|
|
49
|
+
return secret.length > 0 && forms.some((form) => form.includes(secret));
|
|
50
|
+
}
|
|
51
|
+
for (let index = 0; index + SECRET_WINDOW <= secret.length; index += 1) {
|
|
52
|
+
const run = secret.slice(index, index + SECRET_WINDOW);
|
|
53
|
+
if (forms.some((form) => form.includes(run))) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const DECODE_PASSES = 3;
|
|
60
|
+
/** `value` and its percent-decoded forms, until decoding changes nothing. */
|
|
61
|
+
function decodedForms(value) {
|
|
62
|
+
const forms = [value];
|
|
63
|
+
for (let pass = 0; pass < DECODE_PASSES; pass += 1) {
|
|
64
|
+
// Never throws: a `%` without two hex digits stays as it is, and bytes
|
|
65
|
+
// that are not UTF-8 become U+FFFD.
|
|
66
|
+
const decoded = forms[pass].replace(/(?:%[0-9A-Fa-f]{2})+/g, (escapes) => new TextDecoder().decode(Uint8Array.from(escapes.slice(1).split('%'), (hex) => Number.parseInt(hex, 16))));
|
|
67
|
+
if (decoded === forms[pass]) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
forms.push(decoded);
|
|
71
|
+
}
|
|
72
|
+
return forms;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether any string in `value`, keys included, at any depth, shares text
|
|
76
|
+
* with `secrets`. A value that cannot be walked counts as sharing.
|
|
77
|
+
*/
|
|
78
|
+
export function repeatsSecret(value, secrets) {
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
const visit = (current) => {
|
|
81
|
+
if (typeof current === 'string') {
|
|
82
|
+
return secrets.some((secret) => sharesText(current, secret));
|
|
83
|
+
}
|
|
84
|
+
if (!current || typeof current !== 'object' || seen.has(current)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
seen.add(current);
|
|
88
|
+
return Object.entries(current).some(([key, item]) => visit(key) || visit(item));
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
return visit(value);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Every non-empty string value in a JSON request body. */
|
|
98
|
+
export function collectBodyStrings(body, found = []) {
|
|
99
|
+
if (typeof body === 'string') {
|
|
100
|
+
if (body.length > 0) {
|
|
101
|
+
found.push(body);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (body && typeof body === 'object') {
|
|
105
|
+
for (const value of Object.values(body)) {
|
|
106
|
+
collectBodyStrings(value, found);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return found;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=secret-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-text.js","sourceRoot":"","sources":["../src/secret-text.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAK/B,yFAAyF;AACzF,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAE,KAAgB,EAAE,OAA0B;IACnF,I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,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authfn/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Typed browser client for authfn",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc",
|
|
19
19
|
"test": "vitest run",
|
|
20
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
20
21
|
"typecheck": "tsc --noEmit"
|
|
21
22
|
},
|
|
22
23
|
"author": "21n",
|
|
@@ -41,8 +42,11 @@
|
|
|
41
42
|
"@authfn/social-oauth": "0.2.4",
|
|
42
43
|
"@authfn/two-factor": "0.2.1",
|
|
43
44
|
"@types/node": "^22.0.0",
|
|
45
|
+
"esbuild": "0.21.5",
|
|
46
|
+
"fake-indexeddb": "^6.0.0",
|
|
47
|
+
"playwright": "^1.57.0",
|
|
44
48
|
"typescript": "^5.6.0",
|
|
45
49
|
"vitest": "^3.2.4"
|
|
46
50
|
},
|
|
47
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "780684728581f71ad8d104ce355689980ba025ad"
|
|
48
52
|
}
|