@@ -90,6 +90,7 @@ public function request(string $method, string $url, array $options = []): Respo
90
90
$ scheme = $ url ['scheme ' ];
91
91
$ authority = $ url ['authority ' ];
92
92
$ host = parse_url ($ authority , \PHP_URL_HOST );
93
+ $ port = parse_url ($ authority , \PHP_URL_PORT ) ?: ('http: ' === $ scheme ? 80 : 443 );
93
94
$ url = implode ('' , $ url );
94
95
95
96
if (!isset ($ options ['normalized_headers ' ]['user-agent ' ])) {
@@ -163,7 +164,6 @@ public function request(string $method, string $url, array $options = []): Respo
163
164
// First reset any old DNS cache entries then add the new ones
164
165
$ resolve = $ this ->multi ->dnsCache ->evictions ;
165
166
$ this ->multi ->dnsCache ->evictions = [];
166
- $ port = parse_url ($ authority , \PHP_URL_PORT ) ?: ('http: ' === $ scheme ? 80 : 443 );
167
167
168
168
if ($ resolve && 0x072A00 > CurlClientState::$ curlVersion ['version_number ' ]) {
169
169
// DNS cache removals require curl 7.42 or higher
@@ -293,7 +293,7 @@ public function request(string $method, string $url, array $options = []): Respo
293
293
}
294
294
}
295
295
296
- return $ pushedResponse ?? new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host ), CurlClientState::$ curlVersion ['version_number ' ]);
296
+ return $ pushedResponse ?? new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host, $ port ), CurlClientState::$ curlVersion ['version_number ' ]);
297
297
}
298
298
299
299
/**
@@ -373,11 +373,12 @@ private static function readRequestBody(int $length, \Closure $body, string &$bu
373
373
*
374
374
* Work around CVE-2018-1000007: Authorization and Cookie headers should not follow redirects - fixed in Curl 7.64
375
375
*/
376
- private static function createRedirectResolver (array $ options , string $ host ): \Closure
376
+ private static function createRedirectResolver (array $ options , string $ host, int $ port ): \Closure
377
377
{
378
378
$ redirectHeaders = [];
379
379
if (0 < $ options ['max_redirects ' ]) {
380
380
$ redirectHeaders ['host ' ] = $ host ;
381
+ $ redirectHeaders ['port ' ] = $ port ;
381
382
$ redirectHeaders ['with_auth ' ] = $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['headers ' ], static function ($ h ) {
382
383
return 0 !== stripos ($ h , 'Host: ' );
383
384
});
@@ -397,7 +398,8 @@ private static function createRedirectResolver(array $options, string $host): \C
397
398
}
398
399
399
400
if ($ redirectHeaders && $ host = parse_url ('http: ' .$ location ['authority ' ], \PHP_URL_HOST )) {
400
- $ requestHeaders = $ redirectHeaders ['host ' ] === $ host ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
401
+ $ port = parse_url ('http: ' .$ location ['authority ' ], \PHP_URL_PORT ) ?: ('http: ' === $ location ['scheme ' ] ? 80 : 443 );
402
+ $ requestHeaders = $ redirectHeaders ['host ' ] === $ host && $ redirectHeaders ['port ' ] === $ port ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
401
403
curl_setopt ($ ch , \CURLOPT_HTTPHEADER , $ requestHeaders );
402
404
}
403
405
0 commit comments