Repository navigation
feat(web): configurable public addresses for the MCP Apps listeners - #2370
Conversation
…1862) Add MCP_SANDBOX_FULL_ADDRESS and MCP_APP_ORIGIN_FULL_ADDRESS so a reverse proxy or ingress deployment can advertise the sandbox proxy URL and the _meta.ui.domain app origin the browser actually reaches, instead of the bind-derived http://localhost:<port> ones. The process still listens on MCP_SANDBOX_PORT / MCP_APP_ORIGIN_PORT. Both values are validated in public-address.ts and refused (warned, bind- derived address kept) when malformed or when their origin collapses onto the Inspector UI's (or, for the app origin, the sandbox's) — the MCP Apps spec requires host != sandbox origin, and the single-hostname proxy layout is exactly the one that breaks it. Plain http under an https UI is warned. The sandbox proxy page's referrer check was a hardcoded http://localhost|127.0.0.1 pattern no https embedder could match. It now compares the referrer's parsed origin against an exact list injected by the controller, derived from the same filtered allow-list as its frame-ancestors header, with the old loopback check kept only as the no-list fallback. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved listener-port fallback, origin-validation, and sensitive logging issues remain.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds configurable public sandbox and app-origin addresses for reverse-proxy deployments, with validation, proxy security checks, tests, and documentation.
Changes:
- Adds and wires public-address environment variables.
- Validates origins and aligns referrer checks with CSP settings.
- Updates controllers, integration tests, and deployment documentation.
File summaries
| File | Summary |
|---|---|
docs/v1-to-v2-migration.md |
Documents the new environment variables. |
docs/docker.md |
Adds reverse-proxy container guidance. |
clients/web/static/sandbox_proxy.html |
Validates injected embedder origins. |
clients/web/src/test/integration/server/web-server-config.test.ts |
Tests environment and origin configuration. |
clients/web/src/test/integration/server/sandbox-controller.test.ts |
Tests sandbox advertisement and proxy injection. |
clients/web/src/test/integration/server/public-address.test.ts |
Tests public-address validation. |
clients/web/src/test/integration/server/app-origin-controller.test.ts |
Tests public app-origin behavior. |
clients/web/server/web-server-config.ts |
Resolves public-address configuration. Review note: app-origin same-origin validation misses the bind-derived sandbox origin (critical; 1 vote). |
clients/web/server/vite-hono-plugin.ts |
Wires configuration into development startup. |
clients/web/server/server.ts |
Wires configuration into production startup. |
clients/web/server/sandbox-controller.ts |
Advertises configured sandbox URLs. Review note: dynamic port fallback can publish an unreachable configured URL (moderate; 3 votes). |
clients/web/server/public-address.ts |
Validates public addresses. Review note: rejected values may expose credentials or query secrets in warnings (critical; 2 votes). |
clients/web/server/app-origin-controller.ts |
Publishes apps under configured origins. Review note: dynamic port fallback can publish an unreachable public origin (moderate; 3 votes). |
clients/web/README.md |
Documents reverse-proxy deployment. |
Review details
Suppressed comments (1)
clients/web/server/public-address.ts:189
- When no sandbox override is configured,
sandboxUrlisundefinedhere, so this check omits the bind-derived sandbox origin. For example, with the defaults,MCP_APP_ORIGIN_FULL_ADDRESS=http://127.0.0.1:6275is accepted even though the sandbox listens on127.0.0.1:6275; published app URLs then share the sandbox origin and are rejected by the proxy's trusted-origin check (or hit the sandbox listener). Include the known bind-derived sandbox origin when possible, or validate the two listeners after binding.
const trusted = sandboxUrl
? [...allowedOrigins, new URL(sandboxUrl).origin]
: allowedOrigins;
- Files reviewed: 14/14 changed files
- Comments generated: 4
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Never echo a refused value into a warning: credentials, query and fragment are dropped, and an unparseable value is not shown at all. - Do not adopt MCP_SANDBOX_FULL_ADDRESS / MCP_APP_ORIGIN_FULL_ADDRESS after the EADDRINUSE fallback: the reverse proxy still routes them to the pinned port, which another process holds. - Refuse a public app origin equal to any trusted ancestor in the controller, where the real (possibly bind-derived, possibly fallback-port) sandbox origin is known; config time could not see it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
…ce (#1862) Document MCP_SANDBOX_FULL_ADDRESS and MCP_APP_ORIGIN_FULL_ADDRESS in docs/environment-variables.md, note that ALLOWED_ORIGINS is now also the sandbox proxy's embedder allow-list, and list public-address.ts among the web server files. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
Copilot review round 1 — responseAll five findings were real defects in what this PR added; fixed in 4dc5eaa (each inline thread has a reply).
Also in this push, per maintainer request: merged |
There was a problem hiding this comment.
🟡 Changes recommended
Seven unresolved moderate findings remain before approval.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (6)
clients/web/server/app-origin-controller.ts:352
- The fallback check misses the other dynamic case:
port === 0(including the value used whenweb-server-configconverts a port collision) also binds an OS-assigned port. This branch therefore returnspublicOrigineven though the reverse proxy is configured for no stable listener port, making published_meta.ui.domaindocuments unreachable. Reject the public override whenever the effective port is 0, and update the addedport: 0regression test.
if (retriedDynamic) {
console.warn(
`App origin: not using MCP_APP_ORIGIN_FULL_ADDRESS, since it routes to port ${port}, ` +
`which is taken; serving app documents from ${derived} instead.`,
);
clients/web/server/app-origin-controller.ts:347
- When
publicOriginis unset, this early return skips the ancestor collision check for the bind-derived origin. For example, a sandbox override ofhttp://127.0.0.1:6278/sandboxwith the default app-origin port putshttp://127.0.0.1:6278inembedderOrigins, but the app documents are still published on that same origin; the proxy then rejects thesrcwith a console error and falls back to opaquesrcdoc. Check the derived origin againstembedderOriginsas well and refuse or move the dedicated listener with a warning.
if (!publicOrigin) return derived;
clients/web/server/public-address.ts:104
- Although credentials, queries, and fragments are omitted, this still logs
u.pathname. A rejected value can put a secret there—for exampleMCP_APP_ORIGIN_FULL_ADDRESS=https://apps.example.com/tokenis refused as a path but the warning prints/token, and non-http schemes can carry arbitrary payloads in the pathname. Do not echo the pathname (or any untrusted URL value) in validation warnings.
export function describeForLog(raw: string): string {
try {
const u = new URL(raw);
return `"${u.protocol}${u.host ? `//${u.host}` : ""}${u.pathname}"`;
clients/web/server/public-address.ts:217
- This mixed-content warning only considers
allowedOrigins, but app documents are nested inside the sandbox proxy too. If the UI is HTTP,MCP_SANDBOX_FULL_ADDRESSis HTTPS, and the app-origin override is HTTP, no warning is emitted even though the browser blocks the HTTP app document under the HTTPS sandbox. Include the sandbox origin (thetrustedlist) in this check and update the warning text so it does not incorrectly claim the HTTPS origin came fromALLOWED_ORIGINS.
warnMixedContent(APP_ORIGIN_FULL_ADDRESS_ENV, url, allowedOrigins);
clients/web/server/sandbox-controller.ts:352
- This guard only treats an
EADDRINUSEretry as dynamic. Whenport === 0(an explicitMCP_SANDBOX_PORT=0), the listener is also on an unpredictable OS-assigned port, but this still advertisespublicUrl; a reverse proxy cannot route that stable public address to the listener. Treat an effective port of 0 like the retry fallback and keep the bind-derived URL (the addedport: 0public-URL test should be adjusted as well).
if (publicUrl && retriedDynamic) {
console.warn(
`Sandbox: not advertising MCP_SANDBOX_FULL_ADDRESS, since it routes to port ${port}, ` +
`which is taken; advertising ${derivedUrl} instead.`,
);
clients/web/server/web-server-config.ts:490
- A public sandbox URL is also resolved when
sandboxPortis explicitly0. The listener then binds an OS-assigned port, butretriedDynamicremains false and this URL is advertised anyway, leaving a reverse proxy with no stable port to route to. Since the environment contract explicitly allowsMCP_SANDBOX_PORT=0, reject or ignore the public override (with a warning) for this dynamic-port configuration, and add a regression test.
const sandboxPublicUrl = resolveSandboxPublicUrl(
process.env[SANDBOX_FULL_ADDRESS_ENV],
allowedOrigins,
);
- Files reviewed: 15/15 changed files
- Comments generated: 1
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
Addresses Copilot review round 2. A reverse proxy routes a public address to one stable port, so neither MCP_SANDBOX_FULL_ADDRESS nor MCP_APP_ORIGIN_FULL_ADDRESS is used when the listener's port is OS-assigned: an explicit 0, a config-time collision resolved to 0, or the EADDRINUSE fallback. Validation warnings also stop echoing the URL path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
Copilot review round 2 — responseFixed in 925461a: every finding that was a defect in what this PR added. Two suppressed findings are declined below, with reasons. Fixed
Declined
|
There was a problem hiding this comment.
🔵 Needs a closer look
The broad reverse-proxy, origin-validation, listener, and integration changes warrant final human review.
Review details
Suppressed comments (1)
clients/web/static/sandbox_proxy.html:116
- The new referrer check now admits origins from
ALLOWED_ORIGINS, but when a referrer is rejected the message below still tells operators to “update the validation logic.” For the reverse-proxy setup introduced here, the actionable fix is to add the public Inspector origin toALLOWED_ORIGINS; update this message so it points to that configuration instead of suggesting a code change.
if (
!referrerOrigin ||
!(Array.isArray(ALLOWED_EMBEDDER_ORIGINS)
? ALLOWED_EMBEDDER_ORIGINS.includes(referrerOrigin)
: LOOPBACK_EMBEDDER_PATTERN.test(referrerOrigin))
) {
- Files reviewed: 15/15 changed files
- Comments generated: 0 new
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
Addresses Copilot review round 3. The proxy page's rejection message still told operators to "update the validation logic", but the embedder check now reads ALLOWED_ORIGINS, so name that setting as the fix instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
Copilot review round 3 — responseRound 3 generated no inline comments, and one suppressed finding, now fixed in 69ca956.
|
There was a problem hiding this comment.
🔵 Needs a closer look
The moderate mixed-content warning gap remains unresolved, and the test-file rationale header is still missing.
Review details
Suppressed comments (2)
clients/web/server/public-address.ts:218
MCP_APP_ORIGIN_FULL_ADDRESSdocuments are loaded as a child of the sandbox proxy, but this warning only checksallowedOrigins(the Inspector UI origins). With an HTTP UI, an HTTPSMCP_SANDBOX_FULL_ADDRESS, and an HTTP app-origin override, the browser blocks the app as mixed active content inside the HTTPS sandbox and no warning is emitted. Include the sandbox origin's scheme in this check (thetrustedlist above already contains both sets of ancestors) and add a regression case.
warnMixedContent(APP_ORIGIN_FULL_ADDRESS_ENV, url, allowedOrigins);
clients/web/src/test/integration/server/public-address.test.ts:1
- The new test file has no purpose/coverage header, unlike the neighboring integration test for the dedicated app origin (
clients/web/src/test/integration/server/app-origin-controller.test.ts:1-12). Add a short header explaining that this suite validates public-address parsing and its safety warnings so the new file follows the repository's required per-file rationale convention.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
- Files reviewed: 15/15 changed files
- Comments generated: 0 new
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
Addresses Copilot review round 4: every file carries a header explaining its purpose, and this new suite had none. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg Signed-off-by: cliffhall <[email protected]>
Copilot review round 4 — response, and review closedRound 4 generated no inline comments. Two suppressed findings:
With no inline comments left and the only open item a previously declined, out-of-scope class, the review is closed and I am not requesting another round. |
Closes #1862
What
Two new env vars let a reverse-proxy / ingress deployment tell the browser where the MCP Apps listeners actually are, instead of the bind-derived
http://localhost:<port>URLs:MCP_SANDBOX_FULL_ADDRESShttps://inspector-sandbox.example.com/sandbox(a bare origin gets/sandboxappended)sandboxUrlinGET /api/configand the bannerMCP_APP_ORIGIN_FULL_ADDRESShttps://inspector-apps.example.com(origin only)_meta.ui.domainapp documents are published underNeither changes what the process listens on (
MCP_SANDBOX_PORT/MCP_APP_ORIGIN_PORT); the operator routes the public address to the listener. Unset → behavior is unchanged.Why it is more than an env passthrough
This follows the assessment on the issue, which found three things a naive override gets wrong:
https://inspector.example.com/sandbox→:6275— breaks it.public-address.tsrefuses (warns, keeps the bind-derived address) a sandbox URL whose origin is inallowedOrigins, and an app origin equal to the UI's or the sandbox's. It also refuses non-http(s), credentials, query/fragment, wildcards, bracketed IPv6 (not a valid CSP host-source), and a path on the app origin. Plainhttpunder anhttpsallowed origin is warned, not refused (both schemes can legitimately be listed).sandbox_proxy.htmlhardcoded/^http:\/\/(localhost|127\.0\.0\.1)(:|\/|$)/, so the proxy threw on anyhttps://deployment regardless ofALLOWED_ORIGINS. It now comparesnew URL(document.referrer).originagainst an exact list the controller injects when serving the page — built from the sameCSP_HOST_SOURCE-filtered list as itsframe-ancestorsheader, so the two checks admit one set by construction. The value isJSON.stringify'd with<escaped (it lands inside a<script>), substituted with a function-formreplace(no$&interpretation). With no valid list the literal isnulland the page keeps the old loopback check — mirroring the header's own loopback fallback.:6278app-origin listener has the identical problem, andappDocumentEmbedders()feeds the sandbox origin into published documents'frame-ancestors. Both are handled: the app origin has its own override, and because the controllers now advertise the public URL, the embedders list picks up the public sandbox origin automatically.Smaller correctness fix on the way: both controllers' cached
start()parsed the port back out of the advertised URL, which would yieldNaNfor a public URL with no explicit port. They now track the bound port separately. A public address is only adopted once the listener actually binds, so a failed bind still reports no sandbox / makespublishreturn null (srcdoc fallback) rather than advertising a dead URL.Not in scope
clients/web/static) was already fixed by Apps sandbox proxy omitted from package #1859.localhost(crypto.randomUUID), as the assessment found; the README now says to serve the Inspector over HTTPS in that case rather than pretending plain HTTP works.Tests
public-address.test.ts(new): every refusal reason,/sandboxappend, path-prefix passthrough, same-origin refusal for both vars, mixed-content warning.sandbox-controller.test.ts: literal matches theframe-ancestorsfilter;nullfallback;<escaping round-trips;$¬ interpreted; the shipped page contains exactly one placeholder (so a drifted marker can't silently no-op); served page carries the injected list; public URL advertised with the bound port; not advertised when bind fails.app-origin-controller.test.ts: documents published under the public origin and fetchable via the bound listener; not adopted when bind fails.web-server-config.test.ts: unset by default; both resolved against the final allow-list; loopback UI collision refused under the default list; app origin refused when it equals the overridden sandbox's.npm run local:gategreen (includessmoke:web:app, which drives the real proxy page through connect → open app → ready on both the opaque and dedicated-origin paths, so the new referrer allow-list is exercised end to end on loopback).Docs
clients/web/README.md(new "Behind a reverse proxy" block under the MCP Apps caveats, replacing the "Apps can't render behind TLS" sentence),docs/docker.md, and the env table indocs/v1-to-v2-migration.md.No UI change, so no screenshots.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg