fix(web): address Copilot review round 1 on public addresses (#1862)

- 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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HzuzRPJv7M8wGe3wyw5sSg
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-14 00:37:50 -04:00
commit 4dc5eaa6bb

View file

@ -338,9 +338,20 @@ export function createSandboxController(
const urlHost = isAllInterfacesHost(canonicalHost)
? "localhost"
: canonicalHost;
const derivedUrl = `http://${urlHost}:${actualPort}/sandbox`;
// An operator-supplied public URL (#1862) replaces the derived one
// only now that the listener it routes to is actually up.
sandboxUrl = publicUrl ?? `http://${urlHost}:${actualPort}/sandbox`;
// only now that the listener it routes to is actually up — and only
// on the port it was configured for. After the EADDRINUSE fallback
// the proxy still routes the public URL to the PINNED port, which
// someone else holds, so advertising it would send the browser to
// the wrong listener. The derived URL at least works locally.
if (publicUrl && retriedDynamic) {
console.warn(
`Sandbox: not advertising MCP_SANDBOX_FULL_ADDRESS, since it routes to port ${port}, ` +
`which is taken; advertising ${derivedUrl} instead.`,
);
}
sandboxUrl = publicUrl && !retriedDynamic ? publicUrl : derivedUrl;
boundPort = actualPort;
settle({ port: actualPort, url: sandboxUrl });
});