@@ -23,26 +23,29 @@ function stringToArrayBuffer(str: string) {
2323
2424describe ( "request()" , ( ) => {
2525 it ( "Test ReDoS - attack string" , ( ) => {
26- const originalFetch = globalThis . fetch ;
27- globalThis . fetch = async ( url , options ) => {
28- const response = await originalFetch ( url , options ) ;
26+ const fakeFetch = async ( url , options ) => {
27+ const response = await fetch ( url , options ) ;
2928 const fakeHeaders = new Headers ( response . headers ) ;
3029 fakeHeaders . set ( "link" , "<" . repeat ( 100000 ) + ">" ) ;
3130 fakeHeaders . set ( "deprecation" , "true" ) ;
3231 return new Response ( response . body , {
3332 status : response . status ,
3433 statusText : response . statusText ,
35- headers : fakeHeaders
34+ headers : fakeHeaders ,
3635 } ) ;
3736 } ;
3837 const startTime = performance . now ( ) ;
39- request ( "GET /repos/octocat/hello-world" ) ;
38+ request ( "GET /repos/octocat/hello-world" , {
39+ request : { fetch : fakeFetch } ,
40+ } ) ;
4041 const endTime = performance . now ( ) ;
4142 const elapsedTime = endTime - startTime ;
42- const reDosThreshold = 2000 ;
43+ const reDosThreshold = 2000 ;
4344 expect ( elapsedTime ) . toBeLessThanOrEqual ( reDosThreshold ) ;
4445 if ( elapsedTime > reDosThreshold ) {
45- console . warn ( `🚨 Potential ReDoS Attack! getDuration method took ${ elapsedTime . toFixed ( 2 ) } ms, exceeding threshold of ${ reDosThreshold } ms.` ) ;
46+ console . warn (
47+ `🚨 Potential ReDoS Attack! getDuration method took ${ elapsedTime . toFixed ( 2 ) } ms, exceeding threshold of ${ reDosThreshold } ms.` ,
48+ ) ;
4649 }
4750 } ) ;
4851
0 commit comments