|
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;
|
@@ -326,6 +327,8 @@ public static function createFromGlobals(): static
|
326 | 327 | * @param array $files The request files ($_FILES)
|
327 | 328 | * @param array $server The server parameters ($_SERVER)
|
328 | 329 | * @param string|resource|null $content The raw body data
|
| 330 | + * |
| 331 | + * @throws BadRequestException When the URI is invalid |
329 | 332 | */
|
330 | 333 | public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null): static
|
331 | 334 | {
|
@@ -354,6 +357,20 @@ public static function create(string $uri, string $method = 'GET', array $parame
|
354 | 357 | unset($components['fragment']);
|
355 | 358 | }
|
356 | 359 |
|
| 360 | + if (false === $components) { |
| 361 | + throw new BadRequestException('Invalid URI.'); |
| 362 | + } |
| 363 | + |
| 364 | + if (false !== ($i = strpos($uri, '\\')) && $i < strcspn($uri, '?#')) { |
| 365 | + throw new BadRequestException('Invalid URI: A URI cannot contain a backslash.'); |
| 366 | + } |
| 367 | + if (\strlen($uri) !== strcspn($uri, "\r\n\t")) { |
| 368 | + throw new BadRequestException('Invalid URI: A URI cannot contain CR/LF/TAB characters.'); |
| 369 | + } |
| 370 | + if ('' !== $uri && (\ord($uri[0]) <= 32 || \ord($uri[-1]) <= 32)) { |
| 371 | + throw new BadRequestException('Invalid URI: A URI must not start nor end with ASCII control characters or spaces.'); |
| 372 | + } |
| 373 | + |
357 | 374 | if (isset($components['host'])) {
|
358 | 375 | $server['SERVER_NAME'] = $components['host'];
|
359 | 376 | $server['HTTP_HOST'] = $components['host'];
|
|
0 commit comments