{"record":{"id":"0bbcd8245bcde413","repo":"passbolt/passbolt_api","slug":"invalid-public-key-validation-rules-are-missing","errorCode":null,"errorMessage":"Invalid public key validation rules are missing.","messagePattern":"Invalid public key validation rules are missing\\.","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"src/Service/OpenPGP/PublicKeyValidationService.php","lineNumber":148,"sourceCode":"            self::HAS_NO_EXTRA_BREAK_LINE_RULE,\n            self::IS_REVOKED_RULE,\n        ]);\n    }\n\n    /**\n     * @param string $armoredKey user provided data\n     * @param array|null $rules to override default rules\n     * @throws \\App\\Error\\Exception\\CustomValidationException If parsing public key fails\n     * @throws \\App\\Error\\Exception\\CustomValidationException Validation rules fails\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException No public key validation rules\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException Unknown key validation rule\n     * @return array key information (see OpenPGPBackendInterface::getKeyInfo)\n     */\n    public static function parseAndValidatePublicKey(string $armoredKey, ?array $rules = null): array\n    {\n        $rules = $rules ?? self::getDefaultRules();\n        if (!count($rules)) {\n            throw new InternalErrorException('Invalid public key validation rules are missing.');\n        }\n\n        // Parsing check is mandatory and always done first\n        // We don't even try the other rules if this one fails\n        if (!self::isParsableArmoredPublicKey($armoredKey)) {\n            throw new CustomValidationException(__('A valid OpenPGP key must be provided.'), [\n                'armored_key' => [\n                    self::IS_PARSABLE_ARMORED_KEY_RULE => __('The public key could not be parsed.'),\n                ],\n            ]);\n        }\n\n        // Other rules are recommended but not mandatory\n        // As one may want to see what's inside the key info for debugging purpose\n        $keyInfo = self::getPublicKeyInfo($armoredKey);\n        $validationErrors = [];\n        foreach ($rules as $ruleName) {\n            switch ($ruleName) {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/OpenPGP/PublicKeyValidationService.php#L130-L166","documentation":"InternalErrorException thrown by PublicKeyValidationService::parseAndValidatePublicKey when the effective rules array is empty. Rules drive the validation pipeline; an empty set is treated as a programming/configuration error rather than a user-input problem.","triggerScenarios":"Calling parseAndValidatePublicKey($armoredKey, []) with an explicitly empty rules array, or getDefaultRules() returning an empty array because of misconfiguration.","commonSituations":"Passing a custom $rules array built dynamically that ends up empty; config changes removing all key validation rules; refactoring that passes null-coalesced empty arrays.","solutions":["Pass a non-empty rules array, or omit the $rules parameter to use getDefaultRules().","Check the configuration feeding custom rules (e.g. security.gpg key validation settings) is populated.","Validate the rules array with count($rules) > 0 before calling.","Catch InternalErrorException to convert it into a clearer configuration error."],"exampleFix":"// before\n$rules = $this->getConfiguredRules(); // may be empty\nPublicKeyValidationService::parseAndValidatePublicKey($armoredKey, $rules);\n\n// after\n$rules = $this->getConfiguredRules();\nif (!count($rules)) {\n    $rules = PublicKeyValidationService::getDefaultRules();\n}\nPublicKeyValidationService::parseAndValidatePublicKey($armoredKey, $rules);","handlingStrategy":"validation","validationCode":"// PHP\n$rules = $rules ?? PublicKeyValidationService::getDefaultRules();\nif (!count($rules)) {\n    throw new BadConfigurationException('Key validation rules cannot be empty.');\n}","typeGuard":"function hasRules(?array $rules): bool {\n    return is_array($rules) && count($rules) > 0;\n}","tryCatchPattern":"try {\n    PublicKeyValidationService::parseAndValidatePublicKey($armoredKey, $rules);\n} catch (\\Cake\\Http\\Exception\\InternalErrorException $e) {\n    throw new BadConfigurationException('Check key validation rules configuration.');\n}","preventionTips":["Never pass an explicitly empty rules array; fall back to defaults.","Unit-test custom rule providers to guarantee non-empty output.","Keep rule lists in named constants rather than ad-hoc strings."],"tags":["openpgp","validation-rules","configuration","internal-error"],"backgroundTag":"missing-required-config","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}