Skip to content

Commit 738bc9d

Browse files
[HttpClient] Reject 3xx pushed responses
1 parent 6740cdc commit 738bc9d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CurlHttpClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ private static function acceptPushForRequest(string $method, array $options, Pus
378378
}
379379
}
380380

381-
return true;
381+
$statusCode = $pushedResponse->response->getInfo('http_code') ?: 200;
382+
383+
return $statusCode < 300 || 400 <= $statusCode;
382384
}
383385

384386
/**

Response/CurlResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
396396
$info['peer_certificate_chain'] = array_map('openssl_x509_read', array_column($certinfo, 'Cert'));
397397
}
398398

399-
if (300 <= $info['http_code'] && $info['http_code'] < 400) {
399+
if (300 <= $info['http_code'] && $info['http_code'] < 400 && null !== $options) {
400400
if (curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
401401
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
402402
} elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301, 302], true))) {
@@ -418,7 +418,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
418418

419419
$info['redirect_url'] = null;
420420

421-
if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
421+
if (300 <= $statusCode && $statusCode < 400 && null !== $location && null !== $options) {
422422
if ($noContent = 303 === $statusCode || ('POST' === $info['http_method'] && \in_array($statusCode, [301, 302], true))) {
423423
$info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
424424
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $info['http_method']);
@@ -433,7 +433,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
433433

434434
if (401 === $statusCode && isset($options['auth_ntlm']) && 0 === strncasecmp($headers['www-authenticate'][0] ?? '', 'NTLM ', 5)) {
435435
// Continue with NTLM auth
436-
} elseif ($statusCode < 300 || 400 <= $statusCode || null === $location || curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
436+
} elseif ($statusCode < 300 || 400 <= $statusCode || null === $location || null === $options || curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
437437
// Headers and redirects completed, time to get the response's content
438438
$multi->handlesActivity[$id][] = new FirstChunk();
439439

0 commit comments

Comments
 (0)