@@ -2252,11 +2252,9 @@ public function createRequest(): Request
22522252 Request::setFactory (null );
22532253 }
22542254
2255- /**
2256- * @dataProvider getLongHostNames
2257- */
2258- public function testVeryLongHosts ($ host )
2255+ public function testVeryLongHosts ()
22592256 {
2257+ $ host = 'a ' .str_repeat ('.a ' , 40000 );
22602258 $ start = microtime (true );
22612259
22622260 $ request = Request::create ('/ ' );
@@ -2299,14 +2297,6 @@ public static function getHostValidities()
22992297 ];
23002298 }
23012299
2302- public static function getLongHostNames ()
2303- {
2304- return [
2305- ['a ' .str_repeat ('.a ' , 40000 )],
2306- [str_repeat (': ' , 101 )],
2307- ];
2308- }
2309-
23102300 /**
23112301 * @dataProvider methodIdempotentProvider
23122302 */
@@ -2692,6 +2682,71 @@ public function testReservedFlags()
26922682 $ this ->assertNotSame (0b10000000 , $ value , \sprintf ('The constant "%s" should not use the reserved value "0b10000000". ' , $ constant ));
26932683 }
26942684 }
2685+
2686+ /**
2687+ * @dataProvider provideMalformedUrls
2688+ */
2689+ public function testMalformedUrls (string $ url , string $ expectedException )
2690+ {
2691+ $ this ->expectException (BadRequestException::class);
2692+ $ this ->expectExceptionMessage ($ expectedException );
2693+
2694+ Request::create ($ url );
2695+ }
2696+
2697+ public static function provideMalformedUrls (): array
2698+ {
2699+ return [
2700+ ['http://normal.com[@vulndetector.com/ ' , 'Invalid URI: Userinfo is malformed. ' ],
2701+ ['http://[normal.com@vulndetector.com/ ' , 'Invalid URI: Userinfo is malformed. ' ],
2702+ ['http://normal.com@[vulndetector.com/ ' , 'Invalid URI: Host is malformed. ' ],
2703+ ['http://[[normal.com@][vulndetector.com/ ' , 'Invalid URI: Userinfo is malformed. ' ],
2704+ ['http://[vulndetector.com] ' , 'Invalid URI: Host is malformed. ' ],
2705+ ['http://[0:0::vulndetector.com]:80 ' , 'Invalid URI: Host is malformed. ' ],
2706+ ['http://[2001:db8::vulndetector.com] ' , 'Invalid URI: Host is malformed. ' ],
2707+ ['http://[malicious.com] ' , 'Invalid URI: Host is malformed. ' ],
2708+ ['http://[evil.org] ' , 'Invalid URI: Host is malformed. ' ],
2709+ ['http://[internal.server] ' , 'Invalid URI: Host is malformed. ' ],
2710+ ['http://[192.168.1.1] ' , 'Invalid URI: Host is malformed. ' ],
2711+ ['http://192.abc.1.1 ' , 'Invalid URI: Host is malformed. ' ],
2712+ ['http://[localhost] ' , 'Invalid URI: Host is malformed. ' ],
2713+ ["\x80https://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2714+ ['>https://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2715+ ["http \x0b://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2716+ ["https \x80://example.com " , 'Invalid URI: Scheme is malformed. ' ],
2717+ ['http>://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2718+ ['0http://example.com ' , 'Invalid URI: Scheme is malformed. ' ],
2719+ ];
2720+ }
2721+
2722+ /**
2723+ * @dataProvider provideLegitimateUrls
2724+ */
2725+ public function testLegitimateUrls (string $ url )
2726+ {
2727+ $ request = Request::create ($ url );
2728+
2729+ $ this ->assertInstanceOf (Request::class, $ request );
2730+ }
2731+
2732+ public static function provideLegitimateUrls (): array
2733+ {
2734+ return [
2735+ ['http://example.com ' ],
2736+ ['https://example.com ' ],
2737+ ['http://example.com:8080 ' ],
2738+ ['https://example.com:8443 ' ],
2739+ ['http://user:pass@example.com ' ],
2740+ ['http://user:pass@example.com:8080 ' ],
2741+ ['http://user:pass@example.com/path ' ],
2742+ ['http://[2001:db8::1] ' ],
2743+ ['http://[2001:db8::1]:8080 ' ],
2744+ ['http://[2001:db8::1]/path ' ],
2745+ ['http://[::1] ' ],
2746+ ['http://example.com/path ' ],
2747+ [':path ' ],
2748+ ];
2749+ }
26952750}
26962751
26972752class RequestContentProxy extends Request
0 commit comments