@@ -22,6 +22,30 @@ function stringToArrayBuffer(str: string) {
2222}
2323
2424describe ( "request()" , ( ) => {
25+ it ( "Test ReDoS - attack string" , ( ) => {
26+ const originalFetch = globalThis . fetch ;
27+ globalThis . fetch = async ( url , options ) => {
28+ const response = await originalFetch ( url , options ) ;
29+ const fakeHeaders = new Headers ( response . headers ) ;
30+ fakeHeaders . set ( "link" , "<" . repeat ( 100000 ) + ">" ) ;
31+ fakeHeaders . set ( "deprecation" , "true" ) ;
32+ return new Response ( response . body , {
33+ status : response . status ,
34+ statusText : response . statusText ,
35+ headers : fakeHeaders
36+ } ) ;
37+ } ;
38+ const startTime = performance . now ( ) ;
39+ request ( "GET /repos/octocat/hello-world" ) ;
40+ const endTime = performance . now ( ) ;
41+ const elapsedTime = endTime - startTime ;
42+ const reDosThreshold = 2000 ;
43+ expect ( elapsedTime ) . toBeLessThanOrEqual ( reDosThreshold ) ;
44+ if ( elapsedTime > reDosThreshold ) {
45+ console . warn ( `🚨 Potential ReDoS Attack! getDuration method took ${ elapsedTime . toFixed ( 2 ) } ms, exceeding threshold of ${ reDosThreshold } ms.` ) ;
46+ }
47+ } ) ;
48+
2549 it ( "is a function" , ( ) => {
2650 expect ( request ) . toBeInstanceOf ( Function ) ;
2751 } ) ;
0 commit comments