8000 [HttpClient] Fix catching some invalid Location headers · symfony/symfony@7f94d4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f94d4a

Browse files
[HttpClient] Fix catching some invalid Location headers
1 parent 4b8695c commit 7f94d4a
< 8000 /div>

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ private static function createRedirectResolver(array $options, string $host): \C
425425
try {
426426
$locationHasHost = false;
427427
$location = self::parseUrl($location);
428+
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
429+
$url = self::resolveUrl($location, $url);
428430
} catch (InvalidArgumentException $e) {
429431
return null;
430432
}
@@ -446,9 +448,6 @@ private static function createRedirectResolver(array $options, string $host): \C
446448
curl_setopt($ch, \CURLOPT_HTTPHEADER, $redirectHeaders['with_auth']);
447449
}
448450

449-
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
450-
$url = self::resolveUrl($location, $url);
451-
452451
curl_setopt($ch, \CURLOPT_PROXY, self::getProxyUrl($options['proxy'], $url));
453452

454453
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, ?ar
383383

384384
try {
385385
$url = self::parseUrl($location);
386+
$locationHasHost = isset($url['authority']);
387+
$url = self::resolveUrl($url, $info['url']);
386388
} catch (InvalidArgumentException $e) {
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
@@ -494,7 +494,11 @@ public function testNoRedirectWithInvalidLocation()
494494
{
495495
$client = $this->getHttpClient(__FUNCTION__);
496496

497-
$response = $client->request('GET', 'http://localhost:8057/302-no-scheme');
497+
$response = $client->request('GET', 'http://localhost:8057/302?location=localhost:8067');
498+
499+
$this->assertSame(302, $response->getStatusCode());
500+
501+
$response = $client->request('GET', 'http://localhost:8057/302?location=http:localhost');
498502

499503
$this->assertSame(302, $response->getStatusCode());
500504
}

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)
0