From dba90d667485f9f4ffb5b01708eb346a7ab4150a Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Thu, 25 Jul 2024 15:30:48 +0200 Subject: [PATCH] Remove unreached header forwarding code in AphrontRequest Summary: Static code analysis complained `Cannot unset offset 'Authorization'|'Host' on array, array{string, mixed}>.` Per avivey's look at the code, we only ever get headers in the form of X-Hgargs-* in $headers anyway, so the special-case here won't ever happen. Delete this code. Also see similar code at the bottom of `AphrontHTTPProxyResponse.php`. Test Plan: Read the code. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Differential Revision: https://we.phorge.it/D25743 --- src/aphront/AphrontRequest.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/aphront/AphrontRequest.php b/src/aphront/AphrontRequest.php index b66a5ef62e..c1c2ac1974 100644 --- a/src/aphront/AphrontRequest.php +++ b/src/aphront/AphrontRequest.php @@ -894,7 +894,6 @@ final class AphrontRequest extends Phobject { } $headers = array(); - $seen = array(); // NOTE: apache_request_headers() might provide a nicer way to do this, // but isn't available under FCGI until PHP 5.4.0. @@ -920,30 +919,14 @@ final class AphrontRequest extends Phobject { if ($should_forward) { $headers[] = array($key, $value); - $seen[$key] = true; } } // In some situations, this may not be mapped into the HTTP_X constants. // CONTENT_LENGTH is similarly affected, but we trust cURL to take care // of that if it matters, since we're handing off a request body. - if (empty($seen['Content-Type'])) { - if (isset($_SERVER['CONTENT_TYPE'])) { - $headers[] = array('Content-Type', $_SERVER['CONTENT_TYPE']); - } - } - - foreach ($headers as $header) { - list($key, $value) = $header; - switch ($key) { - case 'Host': - case 'Authorization': - // Don't forward these headers, we've already handled them elsewhere. - unset($headers[$key]); - break; - default: - break; - } + if (isset($_SERVER['CONTENT_TYPE'])) { + $headers[] = array('Content-Type', $_SERVER['CONTENT_TYPE']); } foreach ($headers as $header) { -- 2.51.2