|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\HttpFoundation; |
13 | 13 |
|
| 14 | +use Symfony\Component\HttpFoundation\Exception\BadRequestException; |
14 | 15 | use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; |
15 | 16 | use Symfony\Component\HttpFoundation\Exception\JsonException; |
16 | 17 | use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; |
@@ -333,6 +334,8 @@ public static function createFromGlobals() |
333 | 334 | * @param string|resource|null $content The raw body data |
334 | 335 | * |
335 | 336 | * @return static |
| 337 | + * |
| 338 | + * @throws BadRequestException When the URI is invalid |
336 | 339 | */ |
337 | 340 | public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
338 | 341 | { |
@@ -360,6 +363,20 @@ public static function create(string $uri, string $method = 'GET', array $parame |
360 | 363 | unset($components['fragment']); |
361 | 364 | } |
362 | 365 |
|
| 366 | + if (false === $components) { |
| 367 | + throw new BadRequestException('Invalid URI.'); |
| 368 | + } |
| 369 | + |
| 370 | + if (false !== ($i = strpos($uri, '\\')) && $i < strcspn($uri, '?#')) { |
| 371 | + throw new BadRequestException('Invalid URI: A URI cannot contain a backslash.'); |
| 372 | + } |
| 373 | + if (\strlen($uri) !== strcspn($uri, "\r\n\t")) { |
| 374 | + throw new BadRequestException('Invalid URI: A URI cannot contain CR/LF/TAB characters.'); |
| 375 | + } |
| 376 | + if ('' !== $uri && (\ord($uri[0]) <= 32 || \ord($uri[-1]) <= 32)) { |
| 377 | + throw new BadRequestException('Invalid URI: A URI must not start nor end with ASCII control characters or spaces.'); |
| 378 | + } |
| 379 | + |
363 | 380 | if (isset($components['host'])) { |
364 | 381 | $server['SERVER_NAME'] = $components['host']; |
365 | 382 | $server['HTTP_HOST'] = $components['host']; |
|
0 commit comments