{"record":{"id":"6099ab32c8a4efd6","repo":"passbolt/passbolt_api","slug":"unknown-key-validation-rule-0-publickeyvalidationservice","errorCode":null,"errorMessage":"Unknown key validation rule: {0}","messagePattern":"Unknown key validation rule: (.+?)","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"src/Service/OpenPGP/PublicKeyValidationService.php","lineNumber":235,"sourceCode":"                case self::IS_NOT_REVOKED_RULE:\n                    if ($keyInfo['revoked']) {\n                        $validationErrors[$ruleName] = __('The key must not be revoked.');\n                    }\n                    break;\n                case self::HAS_NO_EXTRA_BREAK_LINE_RULE:\n                    if (self::hasExtraBreakline($armoredKey)) {\n                        $msg = __('The armored key must not contain an extra line before the end block.');\n                        $validationErrors[$ruleName] = $msg;\n                    }\n                    break;\n                case self::HAS_MULTIPLE_MAIN_PACKETS_RULE:\n                    if ($keyInfo['public_key_packet_counts'] > 1 || $keyInfo['secret_key_packet_counts'] > 1) {\n                        $msg = __('The armored key must not contain multiple keys.');\n                        $validationErrors[$ruleName] = $msg;\n                    }\n                    break;\n                default:\n                    throw new InternalErrorException(__('Unknown key validation rule: {0}', $ruleName));\n            }\n        }\n\n        // Wrap all errors together in a custom validation exception\n        if (count($validationErrors)) {\n            throw new CustomValidationException(__('The public key could not be validated.'), [\n                'armored_key' => $validationErrors,\n            ]);\n        }\n\n        // Or return key information for further use\n        // for example for it to be saved in a model\n        return $keyInfo;\n    }\n\n    /**\n     * Return true if the date is in the future, false if in the past or not a valid date\n     *","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/OpenPGP/PublicKeyValidationService.php#L217-L253","documentation":"InternalErrorException thrown in the rule-switch of parseAndValidatePublicKey when a rule name is not among the known validation rules (falls into the default case). It guards against typos or stale rule names reaching the validation loop.","triggerScenarios":"Calling parseAndValidatePublicKey with a custom $rules array containing a misspelled or removed rule name, e.g. ['is_parsable_armored_key', 'has_valide_key_size'] (typo), or a rule name from an older passbolt version.","commonSituations":"Custom config or overridden getDefaultRules() after a version upgrade renamed rules; dynamic rule assembly with string constants that drifted.","solutions":["Fix the rule names in the custom rules array to match PublicKeyValidationService's supported rule constants.","Omit the $rules parameter to use the built-in default rules.","After upgrading passbolt, diff custom rules against the current supported rule list.","Catch InternalErrorException and log the offending rule name from the message."],"exampleFix":"// before\n$rules = ['is_parsable_armored_key', 'has_valid_key_type']; // typo / unknown\nPublicKeyValidationService::parseAndValidatePublicKey($key, $rules);\n\n// after\n$rules = ['is_parsable_armored_key', 'has_valid_key_type', 'is_not_revoked'];\n$rules = array_intersect($rules, PublicKeyValidationService::getSupportedRules()); // drop unknown rules\nPublicKeyValidationService::parseAndValidatePublicKey($key, $rules ?: null);","handlingStrategy":"validation","validationCode":"// PHP\n$supported = PublicKeyValidationService::getDefaultRules(); // reference set\n$unknown = array_diff($rules, array_keys(array_flip($supported)));\nif ($unknown) {\n    throw new BadConfigurationException('Unknown rules: ' . implode(',', $unknown));\n}","typeGuard":"function allRulesKnown(array $rules, array $knownRules): bool {\n    return empty(array_diff($rules, $knownRules));\n}","tryCatchPattern":"try {\n    PublicKeyValidationService::parseAndValidatePublicKey($armoredKey, $customRules);\n} catch (\\Cake\\Http\\Exception\\InternalErrorException $e) {\n    Log::error($e->getMessage()); // logs 'Unknown key validation rule: X'\n    throw new BadConfigurationException('Fix unknown key validation rules in config.');\n}","preventionTips":["Reference rule names from class constants, never hand-typed strings.","After upgrades, re-verify custom rules against the supported list.","Write a config smoke test calling parseAndValidatePublicKey with production rules."],"tags":["openpgp","validation-rules","typo","internal-error"],"backgroundTag":"invalid-enum-value","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"}