{"record":{"id":"84a7c41ff369a885","repo":"BookStackApp/BookStack","slug":"unexpected-type-of-key-value-provided","errorCode":null,"errorMessage":"Unexpected type of key value provided","messagePattern":"Unexpected type of key value provided","errorType":"exception","errorClass":"OidcInvalidKeyException","httpStatus":null,"severity":"error","filePath":"app/Access/Oidc/OidcJwtSigningKey.php","lineNumber":29,"sourceCode":"{\n    protected PublicKey $key;\n\n    /**\n     * Can be created either from a JWK parameter array or local file path to load a certificate from.\n     * Examples:\n     * 'file:///var/www/cert.pem'\n     * ['kty' => 'RSA', 'alg' => 'RS256', 'n' => 'abc123...'].\n     *\n     * @throws OidcInvalidKeyException\n     */\n    public function __construct(array|string $jwkOrKeyPath)\n    {\n        if (is_array($jwkOrKeyPath)) {\n            $this->loadFromJwkArray($jwkOrKeyPath);\n        } elseif (str_starts_with($jwkOrKeyPath, 'file://')) {\n            $this->loadFromPath($jwkOrKeyPath);\n        } else {\n            throw new OidcInvalidKeyException('Unexpected type of key value provided');\n        }\n    }\n\n    /**\n     * @throws OidcInvalidKeyException\n     */\n    protected function loadFromPath(string $path): void\n    {\n        try {\n            $key = PublicKeyLoader::load(\n                file_get_contents($path)\n            );\n        } catch (\\Exception $exception) {\n            throw new OidcInvalidKeyException(\"Failed to load key from file path with error: {$exception->getMessage()}\");\n        }\n\n        if (!$key instanceof RSA) {\n            throw new OidcInvalidKeyException('Key loaded from file path is not an RSA key as expected');","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Access/Oidc/OidcJwtSigningKey.php#L11-L47","documentation":"OidcJwtSigningKey's constructor accepts either a JWK array or a 'file://' path string to a key file. Any other argument type (plain string path without file:// scheme, null, object, etc.) cannot be interpreted, so OidcInvalidKeyException is thrown.","triggerScenarios":"new OidcJwtSigningKey('/path/to/key.pem') (missing file:// prefix), new OidcJwtSigningKey($keyString), new OidcJwtSigningKey(null), or passing any non-array, non-file:// value.","commonSituations":"Config value holding a raw filesystem path without the file:// scheme; passing PEM/DER key contents directly as a string; config not loaded so null is passed; wiring the wrong config variable.","solutions":["Prefix the path with 'file://' e.g. new OidcJwtSigningKey('file:///path/to/key.pem')","Pass a decoded JWK array instead if you have the JWK (from discovery jwks_uri)","If you have raw PEM contents, write them to a temp/known file and pass the file:// path","Log/var_dump the value to confirm what is actually being passed (null vs string)"],"exampleFix":"// before\n$key = new OidcJwtSigningKey('/etc/oidc/key.pem');\n// after\n$key = new OidcJwtSigningKey('file:///etc/oidc/key.pem');","handlingStrategy":"type-guard","validationCode":"$value = config('oidc.signing_key');\nif (!(is_array($value) || (is_string($value) && str_starts_with($value, 'file://')))) { throw new \\InvalidArgumentException('key must be JWK array or file:// path'); }","typeGuard":"function isValidKeyValue(mixed $v): bool { return is_array($v) || (is_string($v) && str_starts_with($v, 'file://')); }","tryCatchPattern":"try { $key = new OidcJwtSigningKey($jwkOrPath); } catch (OidcInvalidKeyException $e) { /* fix config: expected JWK array or file:// string */ throw $e; }","preventionTips":["Always pass file:// prefixed paths or decoded JWK arrays","Assert config shape at boot with a schema/config validator","Avoid passing raw PEM contents as strings — write to a file or load JWKs from jwks_uri"],"tags":["php","oidc","key-config"],"backgroundTag":"invalid-signing-key","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}