@@ -2254,9 +2254,9 @@ public function createRequest(): Request
22542254 Request::setFactory (null );
22552255 }
22562256
2257- #[DataProvider('getLongHostNames ' )]
2258- public function testVeryLongHosts ($ host )
2257+ public function testVeryLongHosts ()
22592258 {
2259+ $ host = 'a ' .str_repeat ('.a ' , 40000 );
22602260 $ start = microtime (true );
22612261
22622262 $ request = Request::create ('/ ' );
@@ -2297,14 +2297,6 @@ public static function getHostValidities()
22972297 ];
22982298 }
22992299
2300- public static function getLongHostNames ()
2301- {
2302- return [
2303- ['a ' .str_repeat ('.a ' , 40000 )],
2304- [str_repeat (': ' , 101 )],
2305- ];
2306- }
2307-
23082300 #[DataProvider('methodIdempotentProvider ' )]
23092301 public function testMethodIdempotent ($ method , $ idempotent )
23102302 {
@@ -2677,6 +2669,67 @@ public function testReservedFlags()
26772669 $ this ->assertNotSame (0b10000000 , $ value , \sprintf ('The constant "%s" should not use the reserved value "0b10000000". ' , $ constant ));
26782670 }
26792671 }
2672+
2673+ #[DataProvider('provideMalformedUrls ' )]
2674+ public function testMalformedUrls (string $ url , string $ expectedException )
2675+ {
2676+ $ this ->expectException (BadRequestException::class);
2677+ $ this ->expectExceptionMessage ($ expectedException );
2678+
2679+ Request::create ($ url );
2680+ }
2681+
2682+ public static function provideMalformedUrls (): array
2683+ {
2684+ return [
2685+ ['http://normal.com[@vulndetector.com/ ' , 'Invalid URI: Userinfo is malformed. ' ],
2686+ [
'http://[[email protected] / ' ,
'Invalid URI: Userinfo is malformed. ' ],
2687+ ['http://normal.com@[vulndetector.com/ ' , 'Invalid URI: Host is malformed. ' ],
2688+ ['http://[[normal.com@][vulndetector.com/ ' , 'Invalid URI: Userinfo is malformed. ' ],
2689+ ['http://[vulndetector.com] ' , 'Invalid URI: Host is malformed. ' ],
2690+ ['http://[0:0::vulndetector.com]:80 ' , 'Invalid URI: Host is malformed. ' ],
2691+ ['http://[2001:db8::vulndetector.com] ' , 'Invalid URI: Host is malformed. ' ],
2692+ ['http://[malicious.com] ' , 'Invalid URI: Host is malformed. ' ],
2693+ ['http://[evil.org] ' , 'Invalid URI: Host is malformed. ' ],
2694+ ['http://[internal.server] ' , 'Invalid URI: Host is malformed. ' ],
2695+ ['http://[192.168.1.1] ' , 'Invalid URI: Host is malformed. ' ],
2696+ ['http://192.abc.1.1 ' , 'Invalid URI: Host is malformed. ' ],
2697+ ['http://[localhost] ' , 'Invalid URI: Host is malformed. ' ],
2698+ ["\x80https://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2699+ ['>https://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2700+ ["http \x0b://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2701+ ["https \x80://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2702+ ['http>://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2703+ ['0http://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2704+ ];
2705+ }
2706+
2707+ #[DataProvider('provideLegitimateUrls ' )]
2708+ public function testLegitimateUrls (string $ url )
2709+ {
2710+ $ request = Request::create ($ url );
2711+
2712+ $ this ->assertInstanceOf (Request::class, $ request );
2713+ }
2714+
2715+ public static function provideLegitimateUrls (): array
2716+ {
2717+ return [
2718+ ['http://example.com ' ],
2719+ ['https://example.com ' ],
2720+ ['http://example.com:8080 ' ],
2721+ ['https://example.com:8443 ' ],
2722+ [
'http://user:[email protected] ' ],
2723+ [
'http://user:[email protected] :8080 ' ],
2724+ [
'http://user:[email protected] /path ' ],
2725+ ['http://[2001:db8::1] ' ],
2726+ ['http://[2001:db8::1]:8080 ' ],
2727+ ['http://[2001:db8::1]/path ' ],
2728+ ['http://[::1] ' ],
2729+ ['http://example.com/path ' ],
2730+ [':path ' ],
2731+ ];
2732+ }
26802733}
26812734
26822735class RequestContentProxy extends Request
0 commit comments