passbolt/passbolt_api · error · InternalErrorException

Could not log secret access entry.

Error message

Could not log secret access entry.

What it means

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.

Solutions

  1. Check the chained (previous) exception in server logs for the root cause.
  2. Run migrations for the log plugin: bin/cake migrations migrate --plugin Passbolt/Log (or ddev refresh).
  3. Verify database health (connectivity, disk space, table locks).
  4. Retry after fixing; if only auditing is affected, secrets remain readable once logging works.

Example fix

// before
try {
  $SecretAccesses->createFromSecretEntity($uac, $secret);
} catch (Exception $e) {
  throw new InternalErrorException('Could not log secret access entry.', 500, $e);
}
// after (root-cause fix): ensure log plugin schema is current
// ddev exec bin/cake migrations migrate --plugin Passbolt/Log
Defensive patterns

Strategy: try-catch

Try / catch

try { await api.get(`/resources/${id}.json?contain[secret]=1`); } catch (e) { if (e.status === 500) { adminCheckLogPluginMigrations(); } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Log plugin migrations not run after install/upgrade, database connectivity issues, custom plugins altering the 'secrets' contain shape so createFromSecretEntity receives malformed data.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/571cd4dd8a3fab13. Report an issue: GitHub.

Appendix: source

Thrown at src/Controller/Resources/ResourcesViewController.php:115

     * Log secrets accesses in secretAccesses table.
     *
     * @param array $resource resource
     * @return void
     */
    protected function _logSecretAccesses(array $resource): void
    {
        $Secrets = $this->Resources->getAssociation('Secrets');
        if (!isset($resource['secrets']) || !$Secrets->hasAssociation('SecretAccesses')) {
            return;
        }

        foreach ($resource['secrets'] as $secret) {
            try {
                /** @var \Passbolt\Log\Model\Table\SecretAccessesTable $SecretAccesses */
                $SecretAccesses = $Secrets->getAssociation('SecretAccesses');
                $SecretAccesses->createFromSecretEntity($this->User->getAccessControl(), $secret);
            } catch (Exception $e) {
                throw new InternalErrorException('Could not log secret access entry.', 500, $e);
            }
        }
    }
}

View on GitHub (pinned to 31c1bbc10f)