passbolt/passbolt_api · error · BadRequestException

Invalid id

Error message

Invalid id

What it means

Generic sanity guard in CommentsViewService::view: the provided identifier (comment or foreign key context) failed the uuid/format sanity check, and the generic 'Invalid id' message is surfaced as a 400.

Solutions

  1. Ensure the foreign key is the full UUID of the resource the comments belong to
  2. Fix the client URL builder to interpolate the correct id variable
  3. Validate ids client-side before issuing the request

Example fix

// before
GET /comments/resources/123
// after
GET /comments/resources/9d3f1c0a-8f2e-4b1a-9c3d-2e5f6a7b8c9d
Defensive patterns

Strategy: validation

Validate before calling

use Cake\Validation\Validation;
if (!Validation::uuid($foreignKey)) { /* abort request */ }

Type guard

function isValidUuid(string $id): bool { return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $id) === 1; }

Try / catch

try { $service->view($userId, $model, $foreignKey); } catch (BadRequestException $e) { /* invalid id: fix URL builder */ }

Prevention

When it happens

Trigger: GET /comments/<model>/<foreignKey> where foreignKey is missing, numeric, or otherwise fails Validation::uuid().

Common situations: URL construction bugs omitting the id; passing a slug or external id instead of the passbolt UUID; copy-paste truncation of ids.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at src/Service/Comments/CommentsViewService.php:69

     * @throws \Cake\Http\Exception\BadRequestException if the sanity checks failed
     * @throws \Cake\Http\Exception\NotFoundException if the foreignKey can't be found
     * @param string $userId The currently logged in user's ID
     * @param string $foreignModelName name of the foreign model used for the comment
     * @param string $foreignKey uuid Identifier of the model
     * @param array $options Query options
     * @return \Cake\ORM\Query\SelectQuery
     */
    public function view(string $userId, string $foreignModelName, string $foreignKey, array $options = []): SelectQuery
    {
        $foreignModelName = ucfirst($foreignModelName);
        // Check model sanity.
        if (!in_array($foreignModelName, CommentsTable::ALLOWED_FOREIGN_MODELS)) {
            throw new BadRequestException('Invalid model name');
        }

        // Check uuid sanity.
        if (!Validation::uuid($foreignKey)) {
            throw new BadRequestException('Invalid id');
        }

        try {
            $comments = $this->Comments->findViewForeignComments(
                $userId,
                $foreignModelName,
                $foreignKey,
                $options
            );
        } catch (RecordNotFoundException $e) {
            throw new NotFoundException(__('Could not find comments for the requested model.'));
        }

        return $comments;
    }
}

View on GitHub (pinned to 31c1bbc10f)