diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index b7caa7b5d..e17322de6 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -480,9 +480,18 @@ class Utils{ * @phpstan-return array */ public static function decodeJWT(string $token) : array{ - list($headB64, $payloadB64, $sigB64) = explode(".", $token); + [$headB64, $payloadB64, $sigB64] = explode(".", $token); - return json_decode(base64_decode(strtr($payloadB64, '-_', '+/'), true), true); + $rawPayloadJSON = base64_decode(strtr($payloadB64, '-_', '+/'), true); + if($rawPayloadJSON === false){ + throw new \InvalidArgumentException("Payload base64 is invalid and cannot be decoded"); + } + $decodedPayload = json_decode($rawPayloadJSON, true); + if(!is_array($decodedPayload)){ + throw new \InvalidArgumentException("Decoded payload should be array, " . gettype($decodedPayload) . " received"); + } + + return $decodedPayload; } /**