From 764eaa0ece708263700ff39f333419b550d0449d Mon Sep 17 00:00:00 2001 From: Lio Novelli Date: Thu, 19 Nov 2020 21:55:21 +0100 Subject: [PATCH] Cloudflare issue 3148588: Valid key is rejected as too long. --- src/ApiEndpoints/CloudFlareAPI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ApiEndpoints/CloudFlareAPI.php b/src/ApiEndpoints/CloudFlareAPI.php index 3c25e0a..25804a2 100644 --- a/src/ApiEndpoints/CloudFlareAPI.php +++ b/src/ApiEndpoints/CloudFlareAPI.php @@ -144,7 +144,7 @@ protected function makeRequest($request_type, $api_end_point, $request_params = // This check seems superfluous. However, the Api only returns a http 400 // code. This proactive check gives us more information. $api_key_length = strlen($this->apikey); - $is_api_key_valid = $api_key_length == CloudFlareAPI::API_KEY_LENGTH || $api_key_length == CloudflareAPI::GLOBAL_API_KEY_LENGTH; + $is_api_key_valid = $api_key_length == self:API_KEY_LENGTH || $api_key_length == self::GLOBAL_API_KEY_LENGTH; $is_api_key_alpha_numeric = ctype_alnum($this->apikey); $is_api_key_lower_case = !(preg_match('/[A-Z]/', $this->apikey)); @@ -156,7 +156,7 @@ protected function makeRequest($request_type, $api_end_point, $request_params = throw new CloudFlareInvalidCredentialException('Invalid Api Key: Key can only contain alphanumeric characters.', 403); } - if (!$is_api_key_lower_case) { + if ($api_key_length == self::GLOBAL_API_KEY_LENGTH && !$is_api_key_lower_case) { throw new CloudFlareInvalidCredentialException('Invalid Api Key: Key can only contain lowercase or numerical characters.', 403); }