@@ -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