fix(gateway): reject malformed MCP sandbox policy

This commit is contained in:
Peter Steinberger
2026-07-18 01:59:09 +01:00
parent 6f0f6af62e
commit b351580ba6
+6 -1
View File
@@ -30,9 +30,14 @@ function handleMcpAppSandboxHttpRequest(req: IncomingMessage, res: ServerRespons
return;
}
const encodedCsp = url.searchParams.get("csp");
let csp;
try {
csp = decodeMcpAppSandboxCsp(url.searchParams.get("csp"));
csp = decodeMcpAppSandboxCsp(encodedCsp);
// The decoder also returns undefined for malformed input; only an absent query may use defaults.
if (encodedCsp !== null && !csp) {
throw new Error("invalid MCP App sandbox policy");
}
} catch {
res.statusCode = 400;
res.setHeader("Content-Type", "text/plain; charset=utf-8");