keryx 0.35.1 → 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/util/oauthHandlers/authorize.ts +12 -3
- package/util/oauthTemplates.ts +7 -33
- package/util/scaffold.ts +0 -1
- package/templates/oauth-success.html +0 -38
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
|
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
type AuthPageParams,
|
|
9
9
|
type OAuthTemplates,
|
|
10
10
|
renderAuthPage,
|
|
11
|
-
renderSuccessPage,
|
|
12
11
|
} from "../oauthTemplates";
|
|
13
12
|
import { clientKey, codeKey } from "./keys";
|
|
14
13
|
import type { AuthCode, OAuthClient } from "./types";
|
|
@@ -94,7 +93,7 @@ async function runAuthAction(
|
|
|
94
93
|
* Handle the OAuth authorize form POST (signin/signup).
|
|
95
94
|
*
|
|
96
95
|
* @param req - The incoming form POST request.
|
|
97
|
-
* @param templates - Loaded OAuth HTML templates for rendering the auth
|
|
96
|
+
* @param templates - Loaded OAuth HTML templates for re-rendering the auth page on error.
|
|
98
97
|
* @param origin - The externally-visible origin of this authorization server. Used
|
|
99
98
|
* as the `iss` (issuer) value on the authorization-code redirect per RFC 9207
|
|
100
99
|
* (MCP 2026-07-28 / SEP-2468); matches the `issuer` advertised in AS metadata.
|
|
@@ -177,5 +176,15 @@ export async function handleAuthorizePost(
|
|
|
177
176
|
if (oauthParams.state)
|
|
178
177
|
redirectUrl.searchParams.set("state", oauthParams.state);
|
|
179
178
|
|
|
180
|
-
|
|
179
|
+
// RFC 6749 §4.1.2: complete authorization with a 302 redirect to the client's
|
|
180
|
+
// (already-validated) redirect_uri. A top-level redirect is required for
|
|
181
|
+
// browser-based MCP connectors (e.g. claude.ai): their callback is served with
|
|
182
|
+
// X-Frame-Options/frame-ancestors, so any attempt to reach it from an iframe or
|
|
183
|
+
// sub-context is blocked by the browser and the auth code never arrives — a
|
|
184
|
+
// silent failure. A plain 302 also can't be blocked by CSP or popup rules and
|
|
185
|
+
// works equally for localhost CLI callbacks.
|
|
186
|
+
return new Response(null, {
|
|
187
|
+
status: 302,
|
|
188
|
+
headers: { Location: redirectUrl.toString() },
|
|
189
|
+
});
|
|
181
190
|
}
|
package/util/oauthTemplates.ts
CHANGED
|
@@ -15,7 +15,6 @@ export type FormField = {
|
|
|
15
15
|
|
|
16
16
|
export type OAuthTemplates = {
|
|
17
17
|
authTemplate: string;
|
|
18
|
-
successTemplate: string;
|
|
19
18
|
commonCss: string;
|
|
20
19
|
lionSvg: string;
|
|
21
20
|
};
|
|
@@ -43,7 +42,7 @@ async function resolveTemplate(
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
|
-
* Load
|
|
45
|
+
* Load the OAuth template files, resolving from user project first, then framework.
|
|
47
46
|
* @param rootDir - The user app's root directory.
|
|
48
47
|
* @param packageDir - The framework package directory.
|
|
49
48
|
* @returns An object containing all template strings.
|
|
@@ -52,15 +51,12 @@ export async function loadOAuthTemplates(
|
|
|
52
51
|
rootDir: string,
|
|
53
52
|
packageDir: string,
|
|
54
53
|
): Promise<OAuthTemplates> {
|
|
55
|
-
const [authTemplate,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
],
|
|
62
|
-
);
|
|
63
|
-
return { authTemplate, successTemplate, commonCss, lionSvg };
|
|
54
|
+
const [authTemplate, commonCss, lionSvg] = await Promise.all([
|
|
55
|
+
resolveTemplate("oauth-authorize.html", rootDir, packageDir),
|
|
56
|
+
resolveTemplate("oauth-common.css", rootDir, packageDir),
|
|
57
|
+
resolveTemplate("lion.svg", rootDir, packageDir),
|
|
58
|
+
]);
|
|
59
|
+
return { authTemplate, commonCss, lionSvg };
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
/**
|
|
@@ -213,25 +209,3 @@ export function renderAuthPage(
|
|
|
213
209
|
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
214
210
|
});
|
|
215
211
|
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Render the OAuth success/redirect page.
|
|
219
|
-
* @param redirectUrl - The URL to redirect the user to after authorization.
|
|
220
|
-
* @param templates - Loaded OAuth template strings.
|
|
221
|
-
* @returns An HTML Response.
|
|
222
|
-
*/
|
|
223
|
-
export function renderSuccessPage(
|
|
224
|
-
redirectUrl: string,
|
|
225
|
-
templates: OAuthTemplates,
|
|
226
|
-
): Response {
|
|
227
|
-
const html = Mustache.render(
|
|
228
|
-
templates.successTemplate,
|
|
229
|
-
{ redirectUrl },
|
|
230
|
-
{ commonCss: templates.commonCss, lionSvg: templates.lionSvg },
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
return new Response(html, {
|
|
234
|
-
status: 200,
|
|
235
|
-
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
236
|
-
});
|
|
237
|
-
}
|
package/util/scaffold.ts
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<meta name="redirect-url" content="{{redirectUrl}}" />
|
|
7
|
-
<title>Authorization Successful</title>
|
|
8
|
-
<style>
|
|
9
|
-
{{> commonCss}}
|
|
10
|
-
.container { text-align: center; }
|
|
11
|
-
</style>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<div class="container">
|
|
15
|
-
<div class="checkmark">
|
|
16
|
-
<svg viewBox="0 0 24 24">
|
|
17
|
-
<polyline points="20 6 9 17 4 12"></polyline>
|
|
18
|
-
</svg>
|
|
19
|
-
</div>
|
|
20
|
-
<h2>You're signed in!</h2>
|
|
21
|
-
<p>Authorization was successful.</p>
|
|
22
|
-
<p class="closing">You can close this window.</p>
|
|
23
|
-
</div>
|
|
24
|
-
<div class="lion">{{> lionSvg}}</div>
|
|
25
|
-
<script>
|
|
26
|
-
// Complete the OAuth flow by navigating to the callback URI
|
|
27
|
-
// Use a hidden iframe so the page stays visible
|
|
28
|
-
var iframe = document.createElement("iframe");
|
|
29
|
-
iframe.style.display = "none";
|
|
30
|
-
iframe.src = document.querySelector('meta[name="redirect-url"]').content;
|
|
31
|
-
document.body.appendChild(iframe);
|
|
32
|
-
// Try to close the window after giving the callback time to complete
|
|
33
|
-
setTimeout(function () {
|
|
34
|
-
window.close();
|
|
35
|
-
}, 2000);
|
|
36
|
-
</script>
|
|
37
|
-
</body>
|
|
38
|
-
</html>
|