{"record":{"id":"72d594b1d5e5b358","repo":"passbolt/passbolt_api","slug":"the-metadata-session-key-does-not-exist-or-does-not-belong-72d594","errorCode":null,"errorMessage":"The metadata session key does not exist or does not belong to this user.","messagePattern":"The metadata session key does not exist or does not belong to this user\\.","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataSessionKeyUpdateService.php","lineNumber":75,"sourceCode":"        // 400 invalid user provided data, we expect [modified:<datetime>, data:<string>]\n        $form = new MetadataSessionKeyUpdateForm();\n        if (!$form->execute($data)) {\n            throw new FormValidationException(__('Could not validate the data.'), $form);\n        }\n        $data = $form->getData();\n\n        /** @var \\Passbolt\\Metadata\\Model\\Table\\MetadataSessionKeysTable $metadataSessionKeysTable */\n        $metadataSessionKeysTable = $this->fetchTable('Passbolt/Metadata.MetadataSessionKeys');\n\n        try {\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataSessionKey $metadataSessionKey */\n            $metadataSessionKey = $metadataSessionKeysTable\n                ->find()\n                ->where(['id' => $id, 'user_id' => $uac->getId()])\n                ->firstOrFail();\n        } catch (RecordNotFoundException $e) {\n            // 404 session key entry does not exist or not for current user_id\n            throw new NotFoundException(__('The metadata session key does not exist or does not belong to this user.'));\n        }\n\n        // 400 no changes to be made\n        if ($data['data'] === $metadataSessionKey->get('data')) {\n            throw new BadRequestException(__('The metadata session key data is identical.'));\n        }\n        // 409 if the modified date is not equal to the persisted session key one\n        $asserTime = (new DateTime($data['modified']))->diffInSeconds($metadataSessionKey->get('modified')) === 0;\n        if (!$asserTime) {\n            throw new ConflictException(__('The metadata session key data has changed.'));\n        }\n\n        $metadataSessionKey = $metadataSessionKeysTable->patchEntity(\n            $metadataSessionKey,\n            ['data' => $data['data']],\n            ['accessibleFields' => ['data' => true]]\n        );\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataSessionKeyUpdateService.php#L57-L93","documentation":"update() fetches the session key filtered by both id and user_id; a RecordNotFoundException is converted into a 404 NotFoundException meaning the key does not exist or is not owned by the current user.","triggerScenarios":"Update call with a valid UUID id that does not exist, was deleted, or belongs to another user than the UAC identity.","commonSituations":"Attempting to rotate another user's session key, stale id after key expiry, test fixtures referencing ids from a different database.","solutions":["Confirm the key exists for the authenticated user via the index endpoint","Authenticate as the owning user","Re-create the session key if it expired instead of updating"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"$key = $table->find()->where(['id' => $id, 'user_id' => $uac->getId()])->first(); if (!$key) { throw new RuntimeException('no owned key'); }","typeGuard":"if ($key === null) { return; }","tryCatchPattern":"try { $service->update($uac, $id, $data); } catch (NotFoundException $e) { /* key missing or not owned */ }","preventionTips":["Confirm ownership via the index endpoint before updating","Refresh stale ids after key expiry","Use the owning user's credentials"],"tags":["not-found","ownership","metadata-session-key","update"],"backgroundTag":"resource-not-found","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"}