Skip to content

Commit f222d64

Browse files
committed
Fix MCP Apps marker batch self-attestation bypass
1 parent b67c105 commit f222d64

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

src/lib/mcp/tools/auth-login-app.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe("managed-auth MCP App registration", () => {
271271
},
272272
},
273273
]),
274-
).toBe(true);
274+
).toBe(false);
275275
expect(
276276
initializeDeclaresMcpApps({
277277
jsonrpc: "2.0",

src/lib/mcp/tools/mcp-apps-gate.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@ export const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
1010
const MCP_APPS_MARKER_TTL_SECONDS = 24 * 60 * 60;
1111

1212
/**
13-
* Whether a JSON-RPC payload (single message or batch) is an initialize that
14-
* declares MCP Apps support. The route layer uses this to record the client
15-
* capability, because the stateless streamable-HTTP transport does not expose
16-
* it to later requests.
13+
* Whether a JSON-RPC payload is a standalone initialize request that declares
14+
* MCP Apps support. The route layer records capability only for standalone
15+
* initialize requests so a mixed batch cannot self-attest and invoke app-only
16+
* tools in the same HTTP call.
1717
*/
1818
export function initializeDeclaresMcpApps(body: unknown): boolean {
19-
const messages = Array.isArray(body) ? body : [body];
20-
return messages.some((message) => {
21-
if (!message || typeof message !== "object") return false;
22-
const request = message as {
23-
method?: unknown;
24-
params?: { capabilities?: { extensions?: Record<string, unknown> } };
25-
};
26-
return (
27-
request.method === "initialize" &&
28-
Boolean(request.params?.capabilities?.extensions?.[MCP_APPS_EXTENSION])
29-
);
30-
});
19+
if (!body || typeof body !== "object" || Array.isArray(body)) return false;
20+
const request = body as {
21+
method?: unknown;
22+
params?: { capabilities?: { extensions?: Record<string, unknown> } };
23+
};
24+
return (
25+
request.method === "initialize" &&
26+
Boolean(request.params?.capabilities?.extensions?.[MCP_APPS_EXTENSION])
27+
);
3128
}
3229

3330
/**

0 commit comments

Comments
 (0)