From 7869a7c1b0ae9dc766bf6c0258b4027772575433 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Fri, 26 Jun 2020 14:08:47 +0100 Subject: [PATCH] [ActivityPub][Inbox] With PHP 7.3 we don't need get_all_headers workaround anymore Furthermore, it was broken on Apache2 because the actual function doesn't put the resulting array's key in lowercase. --- plugins/ActivityPub/actions/apinbox.php | 28 +++---------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/plugins/ActivityPub/actions/apinbox.php b/plugins/ActivityPub/actions/apinbox.php index ebce5360b1..425aae2d43 100644 --- a/plugins/ActivityPub/actions/apinbox.php +++ b/plugins/ActivityPub/actions/apinbox.php @@ -90,16 +90,16 @@ class apInboxAction extends ManagedAction common_debug('ActivityPub Inbox: HTTP Signature: Validation will now start!'); - $headers = $this->get_all_headers(); + $headers = getallheaders(); common_debug('ActivityPub Inbox: Request Headers: ' . print_r($headers, true)); - if (!isset($headers['signature'])) { + if (!isset($headers['Signature'])) { common_debug('ActivityPub Inbox: HTTP Signature: Missing Signature header.'); ActivityPubReturn::error('Missing Signature header.', 400); } // Extract the signature properties - $signatureData = HTTPSignature::parseSignatureHeader($headers['signature']); + $signatureData = HTTPSignature::parseSignatureHeader($headers['Signature']); common_debug('ActivityPub Inbox: HTTP Signature Data: ' . print_r($signatureData, true)); if (isset($signatureData['error'])) { common_debug('ActivityPub Inbox: HTTP Signature: ' . json_encode($signatureData, true)); @@ -141,26 +141,4 @@ class apInboxAction extends ManagedAction ActivityPubReturn::error($e->getMessage()); } } - - /** - * Get all HTTP header key/values as an associative array for the current request. - * - * @return array [string] The HTTP header key/value pairs. - * @author PHP Manual Contributed Notes - */ - private function get_all_headers() - { - // If we're running on an Apache2 webserver - if (function_exists('getallheaders')) { - return getallheaders(); - } - // Otherwise, do it manually. - $headers = []; - foreach ($_SERVER as $name => $value) { - if (substr($name, 0, 5) == 'HTTP_') { - $headers[strtolower(str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))))] = $value; - } - } - return $headers; - } }