File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -244,7 +244,7 @@ export function isURL(urlStr: any): boolean {
244244 }
245245 // Validate hostname: Can contain letters, numbers, underscore and dashes separated by a dot.
246246 // Each zone must not start with a hyphen or underscore.
247- if ( ! hostname || ! / ^ [ a - z A - Z 0 - 9 ] + [ \w - ] * ( [ . ] ? [ a - z A - Z 0 - 9 ] + [ \w - ] * ) * $ / . test ( hostname ) ) {
247+ if ( ! hostname || ! / ^ [ a - z A - Z 0 - 9 ] + [ \w - ] * ( \. [ a - z A - Z 0 - 9 ] + [ \w - ] * ) * $ / . test ( hostname ) ) {
248248 return false ;
249249 }
250250 // Allow for pathnames: (/chars+)*/?
Original file line number Diff line number Diff line change @@ -530,3 +530,28 @@ describe('isISODateString()', () => {
530530 expect ( isISODateString ( validISODateString ) ) . to . be . true ;
531531 } ) ;
532532} ) ;
533+
534+ describe ( 'isURL() ReDoS and Long Inputs' , ( ) => {
535+ it ( 'should handle long valid URLs quickly' , function ( ) {
536+ this . timeout ( 1000 ) ;
537+ const longUrl = 'https://' + Array ( 50 ) . fill ( 'a' ) . join ( '.' ) + '.com' ;
538+ expect ( isURL ( longUrl ) ) . to . be . true ;
539+ } ) ;
540+
541+ it ( 'should handle long invalid URLs quickly (ReDoS check)' , function ( ) {
542+ this . timeout ( 1000 ) ;
543+ const longInvalid = 'https://' + 'a' . repeat ( 22 ) + '!' ;
544+ expect ( isURL ( longInvalid ) ) . to . be . false ;
545+ } ) ;
546+
547+ it ( 'should handle very long domain with many segments' , function ( ) {
548+ this . timeout ( 1000 ) ;
549+ const manySegments = 'https://' + Array ( 100 ) . fill ( 'a' ) . join ( '.' ) + '.com' ;
550+ expect ( isURL ( manySegments ) ) . to . be . true ;
551+ } ) ;
552+
553+ it ( 'should reject invalid dot usage caught by strict regex' , function ( ) {
554+ expect ( isURL ( 'https://a.b' ) ) . to . be . true ;
555+ expect ( isURL ( 'https://a..b' ) ) . to . be . false ;
556+ } ) ;
557+ } ) ;
You can’t perform that action at this time.
0 commit comments