Skip to content

Commit b76371e

Browse files
Merge branch '5.4' into 6.4
* 5.4: [HttpFoundation] Revert risk change [HttpClient] Fix catching some invalid Location headers
2 parents 5cc07e7 + 9cfedd8 commit b76371e

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ private static function createRedirectResolver(array $options, string $host, int
421421
try {
422422
$locationHasHost = false;
423423
$location = self::parseUrl($location);
424+
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
425+
$url = self::resolveUrl($location, $url);
424426
} catch (InvalidArgumentException) {
425427
return null;
426428
}
@@ -441,9 +443,6 @@ private static function createRedirectResolver(array $options, string $host, int
441443
curl_setopt($ch, \CURLOPT_HTTPHEADER, $redirectHeaders['with_auth']);
442444
}
443445

444-
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
445-
$url = self::resolveUrl($location, $url);
446-
447446
curl_setopt($ch, \CURLOPT_PROXY, self::getProxyUrl($options['proxy'], $url));
448447

449448
return implode('', $url);

src/Symfony/Component/HttpClient/NativeHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ private static function createRedirectResolver(array $options, string $host, str
383383

384384
try {
385385
$url = self::parseUrl($location);
386+
$locationHasHost = isset($url['authority']);
387+
$url = self::resolveUrl($url, $info['url']);
386388
} catch (InvalidArgumentException) {
387389
$info['redirect_url'] = null;
388390

389391
return null;
390392
}
391393

392-
$locationHasHost = isset($url['authority']);
393-
$url = self::resolveUrl($url, $info['url']);
394394
$info['redirect_url'] = implode('', $url);
395395

396396
if ($info['redirect_count'] >= $maxRedirects) {

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ public function testNoRedirectWithInvalidLocation()
489489
{
490490
$client = $this->getHttpClient(__FUNCTION__);
491491

492-
$response = $client->request('GET', 'http://localhost:8057/302-no-scheme');
492+
$response = $client->request('GET', 'http://localhost:8057/302?location=localhost:8067');
493+
494+
$this->assertSame(302, $response->getStatusCode());
495+
496+
$response = $client->request('GET', 'http://localhost:8057/302?location=http:localhost');
493497

494498
$this->assertSame(302, $response->getStatusCode());
495499
}

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,9 @@ public static function create(string $uri, string $method = 'GET', array $parame
374374
if ('https' === $components['scheme']) {
375375
$server['HTTPS'] = 'on';
376376
$server['SERVER_PORT'] = 443;
377-
} elseif ('http' === $components['scheme']) {
377+
} else {
378378
unset($server['HTTPS']);
379379
$server['SERVER_PORT'] = 80;
380-
} else {
381-
throw new BadRequestException('Invalid URI: http(s) scheme expected.');
382380
}
383381
}
384382

src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
$json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
3333

34-
switch ($vars['REQUEST_URI']) {
34+
switch (parse_url($vars['REQUEST_URI'], \PHP_URL_PATH)) {
3535
default:
3636
exit;
3737

@@ -94,13 +94,8 @@
9494

9595
case '/302':
9696
if (!isset($vars['HTTP_AUTHORIZATION'])) {
97-
header('Location: http://localhost:8057/', true, 302);
98-
}
99-
break;
100-
101-
case '/302-no-scheme':
102-
if (!isset($vars['HTTP_AUTHORIZATION'])) {
103-
header('Location: localhost:8067', true, 302);
97+
$location = $_GET['location'] ?? 'http://localhost:8057/';
98+
header('Location: '.$location, true, 302);
10499
}
105100
break;
106101

0 commit comments

Comments
 (0)