{"record":{"id":"571cd4dd8a3fab13","repo":"passbolt/passbolt_api","slug":"could-not-log-secret-access-entry-resourcesviewcontroller","errorCode":null,"errorMessage":"Could not log secret access entry.","messagePattern":"Could not log secret access entry\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"src/Controller/Resources/ResourcesViewController.php","lineNumber":115,"sourceCode":"     * Log secrets accesses in secretAccesses table.\n     *\n     * @param array $resource resource\n     * @return void\n     */\n    protected function _logSecretAccesses(array $resource): void\n    {\n        $Secrets = $this->Resources->getAssociation('Secrets');\n        if (!isset($resource['secrets']) || !$Secrets->hasAssociation('SecretAccesses')) {\n            return;\n        }\n\n        foreach ($resource['secrets'] as $secret) {\n            try {\n                /** @var \\Passbolt\\Log\\Model\\Table\\SecretAccessesTable $SecretAccesses */\n                $SecretAccesses = $Secrets->getAssociation('SecretAccesses');\n                $SecretAccesses->createFromSecretEntity($this->User->getAccessControl(), $secret);\n            } catch (Exception $e) {\n                throw new InternalErrorException('Could not log secret access entry.', 500, $e);\n            }\n        }\n    }\n}\n","sourceCodeStart":97,"sourceCodeEnd":120,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Controller/Resources/ResourcesViewController.php#L97-L120","documentation":"A 500 thrown by ResourcesViewController::_logSecretAccesses when SecretAccessesTable::createFromSecretEntity() throws while recording an audit entry for a returned secret. The original exception is chained. The resource view succeeded up to this point; the failure is in persisting the secret-access audit record in the passbolt/log plugin tables.","triggerScenarios":"GET /resources/{id}.json?contain[secret]=1 when the SecretAccesses insert fails — missing secret_accesses table/migrations, database outage, or createFromSecretEntity throwing on unexpected secret entity shape.","commonSituations":"Log plugin migrations not run after install/upgrade, database connectivity issues, custom plugins altering the 'secrets' contain shape so createFromSecretEntity receives malformed data.","solutions":["Check the chained (previous) exception in server logs for the root cause.","Run migrations for the log plugin: bin/cake migrations migrate --plugin Passbolt/Log (or ddev refresh).","Verify database health (connectivity, disk space, table locks).","Retry after fixing; if only auditing is affected, secrets remain readable once logging works."],"exampleFix":"// before\ntry {\n  $SecretAccesses->createFromSecretEntity($uac, $secret);\n} catch (Exception $e) {\n  throw new InternalErrorException('Could not log secret access entry.', 500, $e);\n}\n// after (root-cause fix): ensure log plugin schema is current\n// ddev exec bin/cake migrations migrate --plugin Passbolt/Log","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await api.get(`/resources/${id}.json?contain[secret]=1`); } catch (e) { if (e.status === 500) { adminCheckLogPluginMigrations(); } throw e; }","preventionTips":["Ensure Passbolt/Log plugin migrations are applied in all environments","Monitor database writes to secret_accesses table","Treat 500s on secret-containing responses as an audit-log infrastructure problem"],"tags":["http-500","audit-log","secrets","database"],"backgroundTag":"database-write-failed","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"}