feat(web): enforce localhost-only binding; expand loopback origin allow-list (#1796)

Closes #1795.

Enforce localhost-only binding in code (the "never 0.0.0.0" rule was only a spec note): refuse an all-interfaces HOST — across every spelling the OS binds as the wildcard (inet_aton decimal/octal/hex, IPv6, IPv4-mapped, zone-scoped, IDNA/Unicode) — unless DANGEROUSLY_BIND_ALL_INTERFACES=true (Docker's sanctioned opt-in). Fixes the reported stdio-connect 403 by expanding the default loopback origin allow-list to all three interchangeable forms.

Hardening surfaced across an extended review: closes an IDNA/fullwidth wildcard bypass, a blank-ALLOWED_ORIGINS fail-open, and the CLI/TUI OAuth-callback wildcard bind (loopback-only now, RFC 8252); canonicalizes the origin allow-list the way a browser does; derives frame-ancestors from the real embedder list (IPv6-literal exclusion verified in headless Chromium); strictPort on all three bind points; and preserves the CLI exit-code map + JSON envelope through the mcp-inspector --cli launcher path. Shared host normalization lives in core/node/hostUrl.ts. Docs + tests + smokes throughout.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
Cliff Hall 2026-07-26 22:15:10 -04:00 • committed by GitHub
commit cea22d86b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1610 additions and 86 deletions

View file

@ -58,7 +58,7 @@ OAuth redirect URIs must match **exactly** what you register on the authorizatio
| `--client-id <id>` | — | OAuth client ID (static client); overrides `client.json`. |
| `--client-secret <secret>` | — | OAuth client secret (confidential clients); overrides `client.json`. |
| `--client-metadata-url <url>` | — | Client ID Metadata Document URL (CIMD); overrides `client.json`. |
| `--callback-url <url>` | `MCP_OAUTH_CALLBACK_URL` | OAuth redirect/callback listener (default: `http://127.0.0.1:6276/oauth/callback`). |
| `--callback-url <url>` | `MCP_OAUTH_CALLBACK_URL` | OAuth redirect/callback listener (default: `http://127.0.0.1:6276/oauth/callback`). Must bind a **loopback** host (`localhost` / `127.0.0.0/8` / `[::1]`); a non-loopback host hard-errors, since the listener receives the authorization code over plaintext `http`. |
#### Authenticating in the TUI

View file

@ -13,7 +13,25 @@ const isMain =
if (isMain) {
runTui(process.argv).catch((err: unknown) => {
console.error(err);
// Print the message, not the stack — a startup config error (e.g. the
// OAuth callback loopback guard) should read as an actionable message, not
// an internal fault. Matches run-web.ts's house pattern. The stack is still
// available under DEBUG / MCP_DEBUG for a real fault.
console.error("Error:", err instanceof Error ? err.message : err);
// Append the stack only when DEBUG / MCP_DEBUG is *meaningfully* set — "0" /
// "false" / empty read as off, so a stray DEBUG=0 doesn't force a stack.
// (Duplicated from the launcher's `wantsDebugStack` — the two bins can't
// import each other; keep them in sync if this logic changes.)
const debugOn = (v: string | undefined): boolean => {
const s = v?.trim().toLowerCase();
return !!s && s !== "0" && s !== "false";
};
if (
(debugOn(process.env.MCP_DEBUG) || debugOn(process.env.DEBUG)) &&
err instanceof Error
) {
console.error(err.stack);
}
process.exit(1);
});
}

View file

@ -59,7 +59,7 @@ export async function runTui(args?: string[]): Promise<void> {
)
.option(
"--callback-url <url>",
`OAuth redirect/callback listener URL (default: ${DEFAULT_RUNNER_OAUTH_CALLBACK_URL}, or MCP_OAUTH_CALLBACK_URL)`,
`OAuth redirect/callback listener URL; must be loopback (default: ${DEFAULT_RUNNER_OAUTH_CALLBACK_URL}, or MCP_OAUTH_CALLBACK_URL)`,
)
.argument(
"[target...]",