fix: prevent ReDoS vulnerability in UriTemplate regex patterns#1363
Merged
pcarleton merged 2 commits intomodelcontextprotocol:mainfrom Jan 7, 2026
Merged
Conversation
Replace vulnerable regex pattern `([^/]+(?:,[^/]+)*)` with `([^/,]+(?:,[^/,]+)*)` to prevent catastrophic backtracking when processing malicious URIs with many commas. The fix explicitly excludes commas from the first character class, preventing nested quantifier backtracking. Fixes #965
🦋 Changeset detectedLatest commit: 277a216 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
@DevJanderson You need to add a changeset first via https://makenowjust-labs.github.io/recheck/playground/ said the original regex (with |
|
One more thing you may need to send another PR with the same content to the |
This was referenced Jan 7, 2026
|
Any plans for getting a new release with this fix? |
This was referenced Jan 7, 2026
This was referenced Jan 15, 2026
This was referenced Jan 21, 2026
Draft
This was referenced Jan 29, 2026
This was referenced Feb 6, 2026
This was referenced Feb 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the ReDoS (Regular Expression Denial of Service) vulnerability in the
UriTemplateclass (CVE-2026-0621).Problem
The regex patterns for exploded array templates (
{/id*}and{id*}) used([^/]+(?:,[^/]+)*)which causes catastrophic backtracking when processing malicious URIs containing many commas.Solution
Replace the vulnerable pattern with
([^/,]+(?:,[^/,]+)*)- explicitly excluding commas from the first character class prevents nested quantifier backtracking.Changes
packages/core/src/shared/uriTemplate.ts: Fix regex patterns on lines 228 and 238packages/core/test/shared/uriTemplate.test.ts: Add regression tests for ReDoSTesting
All existing tests pass, plus 2 new tests verify the fix prevents ReDoS:
should not be vulnerable to ReDoS with exploded path patternsshould not be vulnerable to ReDoS with exploded simple patternsFixes #965