A Semantic Attack on Google Gemini - Read the Latest Research
The vulnerability is a Regular Expression Denial of Service (ReDoS) within the UriTemplate class of the @modelcontextprotocol/sdk. The analysis of the provided patch commit b392f02ffcf37c088dbd114fedf25026ec3913d3 reveals the root cause. The function UriTemplate.partToRegExp was responsible for generating a regex pattern to parse URI templates. For exploded variables (like {id*}), it created the pattern ([^/]+(?:,[^/]+)*), which contains nested quantifiers. This pattern is subject to catastrophic backtracking.
The patch corrects this by changing the pattern to ([^/,]+(?:,[^/,]+)*), which makes the inner character set [^/,] mutually exclusive with the delimiter ,, thus preventing the backtracking issue. The UriTemplate.match function is the consumer of this vulnerable regex. The test cases added in the patch confirm that calling template.match() with a crafted string (e.g., a long sequence of commas) triggers the vulnerability, causing the function to hang. Therefore, both partToRegExp (which creates the bad regex) and match (which executes it) are the key functions related to this vulnerability.
UriTemplate.partToRegExpsrc/shared/uriTemplate.ts
UriTemplate.matchsrc/shared/uriTemplate.ts
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| @modelcontextprotocol/sdk | npm | < 1.25.2 | 1.25.2 |