Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/busy-weeks-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modelcontextprotocol/core': patch
'@modelcontextprotocol/server': patch
---

Fix ReDoS vulnerability in UriTemplate regex patterns (CVE-2026-0621)
4 changes: 2 additions & 2 deletions packages/core/src/shared/uriTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class UriTemplate {

switch (part.operator) {
case '':
pattern = part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)';
pattern = part.exploded ? '([^/,]+(?:,[^/,]+)*)' : '([^/,]+)';
break;
case '+':
case '#':
Expand All @@ -235,7 +235,7 @@ export class UriTemplate {
pattern = '\\.([^/,]+)';
break;
case '/':
pattern = '/' + (part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)');
pattern = '/' + (part.exploded ? '([^/,]+(?:,[^/,]+)*)' : '([^/,]+)');
break;
default:
pattern = '([^/]+)';
Expand Down
27 changes: 27 additions & 0 deletions packages/core/test/shared/uriTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,32 @@ describe('UriTemplate', () => {
vars[longName] = 'value';
expect(() => template.expand(vars)).not.toThrow();
});

it('should not be vulnerable to ReDoS with exploded path patterns', () => {
// Test for ReDoS vulnerability (CVE-2026-0621)
// See: https://github.com/modelcontextprotocol/typescript-sdk/issues/965
const template = new UriTemplate('{/id*}');
const maliciousPayload = '/' + ','.repeat(50);

const startTime = Date.now();
template.match(maliciousPayload);
const elapsed = Date.now() - startTime;

// Should complete in under 100ms, not hang for seconds
expect(elapsed).toBeLessThan(100);
});

it('should not be vulnerable to ReDoS with exploded simple patterns', () => {
// Test for ReDoS vulnerability with simple exploded operator
const template = new UriTemplate('{id*}');
const maliciousPayload = ','.repeat(50);

const startTime = Date.now();
template.match(maliciousPayload);
const elapsed = Date.now() - startTime;

// Should complete in under 100ms, not hang for seconds
expect(elapsed).toBeLessThan(100);
});
});
});
Loading