{"record":{"id":"6508b8bd7b561bc0","repo":"passbolt/passbolt_api","slug":"the-metadata-key-identifier-should-be-a-uuid","errorCode":null,"errorMessage":"The metadata key identifier should be a UUID.","messagePattern":"The metadata key identifier should be a UUID\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Controller/MetadataPrivateKeysCreateController.php","lineNumber":39,"sourceCode":"use Cake\\Validation\\Validation;\nuse Passbolt\\Metadata\\Service\\MetadataPrivateKeysCreateService;\n\nclass MetadataPrivateKeysCreateController extends AppController\n{\n    /**\n     * Share a metadata key with a given user\n     *\n     * @param string $id metadata key id\n     * @return void\n     */\n    public function create(string $id)\n    {\n        $this->assertJson();\n        $this->assertNotEmptyArrayData();\n        $this->User->assertIsAdmin();\n\n        if (!Validation::uuid($id)) {\n            throw new BadRequestException(__('The metadata key identifier should be a UUID.'));\n        }\n        $data = $this->request->getData();\n\n        $created = (new MetadataPrivateKeysCreateService())->create($this->User->getAccessControl(), $id, $data);\n        $this->success(__('The operation was successful.'), $created);\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":47,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Controller/MetadataPrivateKeysCreateController.php#L21-L47","documentation":"Format guard when sharing a metadata key with a user: the id route parameter (the metadata key id) fails Validation::uuid(), so the request is rejected with 400 before the private key creation service is called.","triggerScenarios":"Creating a metadata private key where the {metadataKeyId} path segment is not a valid UUID (fingerprint, empty string, numeric id).","commonSituations":"Using the OpenPGP fingerprint instead of the passbolt metadata key UUID; URL templating that left a placeholder unfilled; ids copied from the wrong entity.","solutions":["Use the metadata key UUID from GET /metadata/keys in the path.","Fix URL template interpolation so the id resolves.","Validate the id with a UUID regex before calling."],"exampleFix":"// before\npost(`/metadata/private/${fingerprint}/private-keys`, body);\n// after\npost(`/metadata/private/${metadataKeyId}/private-keys`, body); // metadataKeyId is a UUID","handlingStrategy":"validation","validationCode":"if (!isUuid(metadataKeyId)) throw new Error('metadata key id must be a UUID');","typeGuard":"const isUuid = (v) => typeof v === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);","tryCatchPattern":"try { await api.post(`/metadata/private/${metadataKeyId}/private-keys`, body); } catch (e) { if (e.response?.status === 400) { metadataKeyId = (await api.get('/metadata/keys')).find(k => k.fingerprint === fingerprint).id; return retry(); } throw e; }","preventionTips":["Map fingerprints to server-issued UUIDs before API calls.","Validate path segments client-side.","Resolve ids from list endpoints rather than constructing them."],"tags":["uuid","validation","api","bad-request"],"backgroundTag":"invalid-identifier-format","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"}