Skip to content

Commit d68cb4b

Browse files
authored
Merge branch 'main' into feat/v1x-release-workflow
2 parents 9f27dd8 + 1014d9f commit d68cb4b

File tree

17 files changed

+824
-18
lines changed

17 files changed

+824
-18
lines changed

.changeset/busy-weeks-hang.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modelcontextprotocol/core': patch
3+
'@modelcontextprotocol/server': patch
4+
---
5+
6+
Fix ReDoS vulnerability in UriTemplate regex patterns (CVE-2026-0621)

.changeset/cyan-cycles-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
missing change for fix(client): replace body.cancel() with text() to prevent hanging

.changeset/strong-hairs-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
add application/json header for notifications

.github/workflows/conformance.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Conformance Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
client-conformance:
14+
runs-on: ubuntu-latest
15+
continue-on-error: true # Non-blocking initially
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v4
20+
with:
21+
run_install: false
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 24
25+
cache: pnpm
26+
cache-dependency-path: pnpm-lock.yaml
27+
- run: pnpm install
28+
- run: pnpm run build:all
29+
- run: pnpm run test:conformance:client:all

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@
2929
"lint:all": "pnpm -r lint",
3030
"lint:fix:all": "pnpm -r lint:fix",
3131
"check:all": "pnpm -r typecheck && pnpm -r lint",
32-
"test:all": "pnpm -r test"
32+
"test:all": "pnpm -r test",
33+
"test:conformance:client": "conformance client --command 'npx tsx src/conformance/everything-client.ts'",
34+
"test:conformance:client:all": "conformance client --command 'npx tsx src/conformance/everything-client.ts' --suite all",
35+
"test:conformance:client:run": "npx tsx src/conformance/everything-client.ts"
3336
},
3437
"devDependencies": {
3538
"@cfworker/json-schema": "catalog:runtimeShared",
3639
"@changesets/changelog-github": "^0.5.2",
3740
"@changesets/cli": "^2.29.8",
3841
"@eslint/js": "catalog:devTools",
42+
"@modelcontextprotocol/client": "workspace:^",
43+
"@modelcontextprotocol/conformance": "0.1.9",
3944
"@types/content-type": "catalog:devTools",
4045
"@types/cors": "catalog:devTools",
4146
"@types/cross-spawn": "catalog:devTools",
@@ -56,7 +61,8 @@
5661
"typescript": "catalog:devTools",
5762
"typescript-eslint": "catalog:devTools",
5863
"vitest": "catalog:devTools",
59-
"ws": "catalog:devTools"
64+
"ws": "catalog:devTools",
65+
"zod": "catalog:runtimeShared"
6066
},
6167
"resolutions": {
6268
"strip-ansi": "6.0.1"

packages/client/src/client/auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ export async function discoverOAuthProtectedResourceMetadata(
670670
});
671671

672672
if (!response || response.status === 404) {
673-
await response?.body?.cancel();
673+
await response?.text?.().catch(() => {});
674674
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
675675
}
676676

677677
if (!response.ok) {
678-
await response.body?.cancel();
678+
await response.text?.().catch(() => {});
679679
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
680680
}
681681
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
@@ -803,12 +803,12 @@ export async function discoverOAuthMetadata(
803803
});
804804

805805
if (!response || response.status === 404) {
806-
await response?.body?.cancel();
806+
await response?.text?.().catch(() => {});
807807
return undefined;
808808
}
809809

810810
if (!response.ok) {
811-
await response.body?.cancel();
811+
await response.text?.().catch(() => {});
812812
throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
813813
}
814814

@@ -918,7 +918,7 @@ export async function discoverAuthorizationServerMetadata(
918918
}
919919

920920
if (!response.ok) {
921-
await response.body?.cancel();
921+
await response.text?.().catch(() => {});
922922
// Continue looking for any 4xx response code.
923923
if (response.status >= 400 && response.status < 500) {
924924
continue; // Try next URL

packages/client/src/client/sse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class SSEClientTransport implements Transport {
260260

261261
const response = await (this._fetch ?? fetch)(this._endpoint, init);
262262
if (!response.ok) {
263-
const text = await response.text().catch(() => null);
263+
const text = await response.text?.().catch(() => null);
264264

265265
if (response.status === 401 && this._authProvider) {
266266
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
@@ -285,7 +285,7 @@ export class SSEClientTransport implements Transport {
285285
}
286286

287287
// Release connection - POST responses don't have content we need
288-
await response.body?.cancel();
288+
await response.text?.().catch(() => {});
289289
} catch (error) {
290290
this.onerror?.(error as Error);
291291
throw error;

packages/client/src/client/streamableHttp.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class StreamableHTTPClientTransport implements Transport {
235235
});
236236

237237
if (!response.ok) {
238-
await response.body?.cancel();
238+
await response.text?.().catch(() => {});
239239

240240
if (response.status === 401 && this._authProvider) {
241241
// Need to authenticate
@@ -495,7 +495,7 @@ export class StreamableHTTPClientTransport implements Transport {
495495
}
496496

497497
if (!response.ok) {
498-
const text = await response.text().catch(() => null);
498+
const text = await response.text?.().catch(() => null);
499499

500500
if (response.status === 401 && this._authProvider) {
501501
// Prevent infinite recursion when server returns 401 after successful auth
@@ -568,7 +568,7 @@ export class StreamableHTTPClientTransport implements Transport {
568568

569569
// If the response is 202 Accepted, there's no body to process
570570
if (response.status === 202) {
571-
await response.body?.cancel();
571+
await response.text?.().catch(() => {});
572572
// if the accepted notification is initialized, we start the SSE stream
573573
// if it's supported by the server
574574
if (isInitializedNotification(message)) {
@@ -603,12 +603,12 @@ export class StreamableHTTPClientTransport implements Transport {
603603
this.onmessage?.(msg);
604604
}
605605
} else {
606-
await response.body?.cancel();
606+
await response.text?.().catch(() => {});
607607
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
608608
}
609609
} else {
610610
// No requests in message but got 200 OK - still need to release connection
611-
await response.body?.cancel();
611+
await response.text?.().catch(() => {});
612612
}
613613
} catch (error) {
614614
this.onerror?.(error as Error);
@@ -647,7 +647,7 @@ export class StreamableHTTPClientTransport implements Transport {
647647
};
648648

649649
const response = await (this._fetch ?? fetch)(this._url, init);
650-
await response.body?.cancel();
650+
await response.text?.().catch(() => {});
651651

652652
// We specifically handle 405 as a valid response according to the spec,
653653
// meaning the server does not support explicit session termination

packages/core/src/shared/uriTemplate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class UriTemplate {
225225

226226
switch (part.operator) {
227227
case '':
228-
pattern = part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)';
228+
pattern = part.exploded ? '([^/,]+(?:,[^/,]+)*)' : '([^/,]+)';
229229
break;
230230
case '+':
231231
case '#':
@@ -235,7 +235,7 @@ export class UriTemplate {
235235
pattern = '\\.([^/,]+)';
236236
break;
237237
case '/':
238-
pattern = '/' + (part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)');
238+
pattern = '/' + (part.exploded ? '([^/,]+(?:,[^/,]+)*)' : '([^/,]+)');
239239
break;
240240
default:
241241
pattern = '([^/]+)';

packages/core/test/shared/uriTemplate.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,32 @@ describe('UriTemplate', () => {
284284
vars[longName] = 'value';
285285
expect(() => template.expand(vars)).not.toThrow();
286286
});
287+
288+
it('should not be vulnerable to ReDoS with exploded path patterns', () => {
289+
// Test for ReDoS vulnerability (CVE-2026-0621)
290+
// See: https://github.com/modelcontextprotocol/typescript-sdk/issues/965
291+
const template = new UriTemplate('{/id*}');
292+
const maliciousPayload = '/' + ','.repeat(50);
293+
294+
const startTime = Date.now();
295+
template.match(maliciousPayload);
296+
const elapsed = Date.now() - startTime;
297+
298+
// Should complete in under 100ms, not hang for seconds
299+
expect(elapsed).toBeLessThan(100);
300+
});
301+
302+
it('should not be vulnerable to ReDoS with exploded simple patterns', () => {
303+
// Test for ReDoS vulnerability with simple exploded operator
304+
const template = new UriTemplate('{id*}');
305+
const maliciousPayload = ','.repeat(50);
306+
307+
const startTime = Date.now();
308+
template.match(maliciousPayload);
309+
const elapsed = Date.now() - startTime;
310+
311+
// Should complete in under 100ms, not hang for seconds
312+
expect(elapsed).toBeLessThan(100);
313+
});
287314
});
288315
});

0 commit comments

Comments
 (0)