keryx 0.35.2 → 0.35.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.
- package/package.json +1 -1
- package/util/oauth.ts +38 -9
package/package.json
CHANGED
package/util/oauth.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Schemes that must never be accepted as redirect URIs. They can execute code or
|
|
3
|
+
* read local resources if a client (or the browser) ever navigates to them, so
|
|
4
|
+
* we reject them outright even though `/oauth/register` is open (RFC 7591).
|
|
5
|
+
*/
|
|
6
|
+
const DANGEROUS_SCHEMES = new Set([
|
|
7
|
+
"javascript:",
|
|
8
|
+
"data:",
|
|
9
|
+
"vbscript:",
|
|
10
|
+
"file:",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validate an OAuth redirect URI. Rules by scheme:
|
|
15
|
+
* - `https:` — allowed for any host (remote web callbacks).
|
|
16
|
+
* - `http:` — allowed only for loopback hosts (`localhost`, `127.0.0.1`, `[::1]`).
|
|
17
|
+
* - `javascript:` / `data:` / `vbscript:` / `file:` — always rejected.
|
|
18
|
+
* - any other scheme — treated as a private-use / custom URI scheme for a native
|
|
19
|
+
* app (e.g. `vscode://`, `cursor://`, `com.example.app:/callback`) and allowed
|
|
20
|
+
* per RFC 8252 §7.1. Reverse-DNS form is not required, since real clients
|
|
21
|
+
* (`vscode://`) don't use it.
|
|
22
|
+
*
|
|
23
|
+
* Fragments and userinfo are rejected for every scheme.
|
|
4
24
|
*
|
|
5
25
|
* @param uri - The redirect URI to validate.
|
|
6
26
|
* @returns `{ valid: true }` or `{ valid: false, error: string }`.
|
|
@@ -24,18 +44,27 @@ export function validateRedirectUri(uri: string): {
|
|
|
24
44
|
return { valid: false, error: "Redirect URI must not contain userinfo" };
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
parsed.hostname === "localhost" ||
|
|
29
|
-
parsed.hostname === "127.0.0.1" ||
|
|
30
|
-
parsed.hostname === "[::1]";
|
|
31
|
-
|
|
32
|
-
if (!isLocalhost && parsed.protocol !== "https:") {
|
|
47
|
+
if (DANGEROUS_SCHEMES.has(parsed.protocol)) {
|
|
33
48
|
return {
|
|
34
49
|
valid: false,
|
|
35
|
-
error:
|
|
50
|
+
error: `Redirect URI scheme "${parsed.protocol}" is not allowed`,
|
|
36
51
|
};
|
|
37
52
|
}
|
|
38
53
|
|
|
54
|
+
if (parsed.protocol === "http:") {
|
|
55
|
+
const isLoopback =
|
|
56
|
+
parsed.hostname === "localhost" ||
|
|
57
|
+
parsed.hostname === "127.0.0.1" ||
|
|
58
|
+
parsed.hostname === "[::1]";
|
|
59
|
+
if (!isLoopback) {
|
|
60
|
+
return {
|
|
61
|
+
valid: false,
|
|
62
|
+
error: "Redirect URI must use HTTPS for non-localhost URIs",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// https: and private-use/custom schemes (native apps) are allowed.
|
|
39
68
|
return { valid: true };
|
|
40
69
|
}
|
|
41
70
|
|