🔒 fix: Upgrade the MCP SDK Past the OAuth Credential Leak (GHSA-6qxp-vccf-f47h) (#17015)

Bump @modelcontextprotocol/sdk from ^1.30.0 to ^1.32.1 in api and
packages/api. 1.31.0 binds stored OAuth credentials to the issuing
authorization server; LibreChat does not use the affected auth()/
authProvider path and already pins refreshes to the stored token endpoint.

1.32.0 makes the client transports follow same-origin redirects
themselves, which would re-issue requests the connection fetch declined
(hop cap, reauthorized tools/call). Set redirectPolicy: 'follow' so
redirects stay with the connection fetch, and cover both transports with
real-SDK tests.
This commit is contained in:
Danny Avila 2026-10-16 07:01:25 -04:00 • committed by GitHub
parent 27e8930d52
commit 685c8b5b43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 107 additions and 8 deletions

View file

@ -43,7 +43,7 @@
"@librechat/api": "*",
"@librechat/data-schemas": "*",
"@microsoft/microsoft-graph-client": "^3.0.7",
"@modelcontextprotocol/sdk": "^1.30.0",
"@modelcontextprotocol/sdk": "^1.32.1",
"@node-saml/passport-saml": "^5.1.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation-express": "^0.56.0",

10
package-lock.json generated
View file

@ -69,7 +69,7 @@
"@librechat/api": "*",
"@librechat/data-schemas": "*",
"@microsoft/microsoft-graph-client": "^3.0.7",
"@modelcontextprotocol/sdk": "^1.30.0",
"@modelcontextprotocol/sdk": "^1.32.1",
"@node-saml/passport-saml": "^5.1.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation-express": "^0.56.0",
@ -9945,9 +9945,9 @@
}
},
"node_modules/@modelcontextprotocol/sdk": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.30.0.tgz",
"integrity": "sha512-xKd8OIzlqNzcqcNumGAa6g+PW2kjD5vrpcKOnfldAUPP3j7lnqMPwlTXQm8gF+UwH72z0lqaRbjr9hqGz0eITA==",
"version": "1.32.1",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.1.tgz",
"integrity": "sha512-2DdE+SJDtzLEEWzY1ZjY7Q+VcPhcV1KisD3zI4u0XZyktsjHum1mwbMI+JaulUBi2OZk+KJAi2uPXzxichPkdw==",
"license": "MIT",
"dependencies": {
"@hono/node-server": "^1.19.9 || ^2.0.5",
@ -40731,7 +40731,7 @@
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.0.4",
"@librechat/data-schemas": "*",
"@modelcontextprotocol/sdk": "^1.30.0",
"@modelcontextprotocol/sdk": "^1.32.1",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation-express": "^0.56.0",
"@opentelemetry/instrumentation-http": "^0.207.0",

View file

@ -122,7 +122,7 @@
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.0.4",
"@librechat/data-schemas": "*",
"@modelcontextprotocol/sdk": "^1.30.0",
"@modelcontextprotocol/sdk": "^1.32.1",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation-express": "^0.56.0",
"@opentelemetry/instrumentation-http": "^0.207.0",

View file

@ -819,6 +819,97 @@ describe('scheduled dispatch authority across redirect hops', () => {
);
});
/**
* The SDK transports follow same-origin redirects themselves unless `redirectPolicy` leaves them
* to the fetch. These run the real transports so a redirect `createFetchFunction` declined can
* never be re-issued by the SDK.
*/
describe('SDK transports defer redirects to the connection fetch', () => {
let conn: MCPConnection | null = null;
let server: RawResponseServer | undefined;
afterEach(async () => {
await safeDisconnect(conn);
conn = null;
await server?.close();
server = undefined;
});
it.each([307, 308] as const)(
'does not let the streamable-http transport repeat a tools/call answered with %s',
async (status) => {
const sessions = new Map<string, StreamableHTTPServerTransport>();
const toolCallPaths: string[] = [];
server = await createRawResponseServer(async (req, res) => {
const chunks: Buffer[] = [];
for await (const chunk of req) chunks.push(chunk as Buffer);
const body: { method?: string } | undefined = chunks.length
? JSON.parse(Buffer.concat(chunks).toString())
: undefined;
if (body?.method === 'tools/call') {
toolCallPaths.push(req.url!);
res.writeHead(status, { Location: '/replayed' });
res.end();
return;
}
const sid = req.headers['mcp-session-id'] as string | undefined;
let transport = sid ? sessions.get(sid) : undefined;
if (!transport) {
transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID() });
const mcp = new McpServer({ name: 'no-replay', version: '0.0.1' });
mcp.tool('read', 'Reads once', {}, async () => ({
content: [{ type: 'text', text: 'read' }],
}));
await mcp.connect(transport);
}
await transport.handleRequest(req, res, body);
if (transport.sessionId && !sessions.has(transport.sessionId)) {
sessions.set(transport.sessionId, transport);
}
});
conn = new MCPConnection({
serverName: 'sdk-no-replay',
serverConfig: { type: 'streamable-http', url: new URL('mcp', server.url).href },
resolveRequestHeaders: jest.fn(async () => ({ authorization: 'Bearer occurrence' })),
useSSRFProtection: false,
});
try {
await conn.connect();
await expect(
conn.client.callTool({ name: 'read', arguments: {} }, undefined, { timeout: 3000 }),
).rejects.toThrow();
expect(toolCallPaths).toEqual(['/mcp']);
} finally {
await closeMCPSessions(sessions);
}
},
);
it('does not let the SSE transport follow a same-origin redirect of its stream', async () => {
const paths: string[] = [];
server = await createRawResponseServer((req, res) => {
paths.push(req.url!);
if (req.url === '/sse') {
res.writeHead(302, { Location: '/moved' });
res.end();
return;
}
res.writeHead(200, { 'Content-Type': 'text/event-stream' });
res.end();
});
conn = new MCPConnection({
serverName: 'sse-no-follow',
serverConfig: { type: 'sse', url: new URL('sse', server.url).href },
useSSRFProtection: false,
});
await expect(conn.connect()).rejects.toThrow();
expect(paths.length).toBeGreaterThan(0);
expect(paths.every((path) => path === '/sse')).toBe(true);
});
});
describe('MCP SSRF protection – 307/308 redirect following', () => {
let server: TestServer | undefined;
let conn: MCPConnection | null;

View file

@ -3353,7 +3353,7 @@ describe('MCPOAuthHandler - Configurable OAuth Metadata', () => {
);
expect(mockExchangeAuthorization).toHaveBeenCalledTimes(1);
expect(mockExchangeAuthorization.mock.calls[0][1].resource?.href).toBe(
expect(String(mockExchangeAuthorization.mock.calls[0][1].resource)).toBe(
'https://example.com/mcp',
);
});

View file

@ -162,6 +162,12 @@ const TOOL_LIST_REFRESH_RETRY_BASE_MS = 250;
const TOOL_LIST_REFRESH_RETRY_MAX_MS = 30_000;
/** Max 307/308 redirects to follow per request (prevents redirect loops) */
const MAX_REDIRECTS = 5;
/**
* `createFetchFunction` is the only redirect authority (SSRF checks, the hop cap, cross-origin
* credential stripping, no tool-call replay). `'follow'` leaves redirects to that fetch, so the
* SDK's own same-origin follower cannot re-issue a request it declined.
*/
const SDK_REDIRECT_POLICY = 'follow' as const;
const DEFAULT_MCP_STREAMABLE_HTTP_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
const DEFAULT_MCP_STREAMABLE_HTTP_MAX_LINE_BYTES = 5 * 1024 * 1024;
@ -1829,6 +1835,7 @@ export class MCPConnection extends EventEmitter {
Object.keys(headers).map((key) => key.toLowerCase()),
);
const transport = new SSEClientTransport(url, {
redirectPolicy: SDK_REDIRECT_POLICY,
requestInit: {
/** User/OAuth headers override SSE defaults */
headers: { ...SSE_REQUEST_HEADERS, ...headers },
@ -1956,6 +1963,7 @@ export class MCPConnection extends EventEmitter {
Object.keys(headers).map((key) => key.toLowerCase()),
);
const transport = new StreamableHTTPClientTransport(url, {
redirectPolicy: SDK_REDIRECT_POLICY,
requestInit: {
headers,
signal: abortController.signal,