Skip to content

cms-api: Validate UUID format of AffectedEntity id args before loading the entity - #6207

Open
VP-DS wants to merge 2 commits into
mainfrom
validate-uuid-in-affected-entity-check
Open

cms-api: Validate UUID format of AffectedEntity id args before loading the entity#6207
VP-DS wants to merge 2 commits into
mainfrom
validate-uuid-in-affected-entity-check

Conversation

@VP-DS

@VP-DS VP-DS commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Problem

@AffectedEntity() loads the affected entity in UserPermissionsGuard to determine the content scope for the permission check. Guards run before pipes, so validation decorators such as @IsUUID() haven't run at that point. A malformed id therefore reached PostgreSQL through findOneOrFail(), which failed with invalid input syntax for type uuid (22P02). Instead of a validation error, the client got an internal server error.

Solution

Validate the id arguments in ContentScopeService before the entity is loaded:

  • idArg values are checked with isUUID() when the affected entity's primary key is a uuid column. The primary key type is read from the MikroORM metadata, so both @PrimaryKey({ type: "uuid" }) and @PrimaryKey({ columnType: "uuid" }) are covered. Entities with a non-uuid primary key are unaffected.
  • pageTreeNodeIdArg values are checked as well, as they were exposed to the same failure in pageTreeApi.getNode().

Malformed ids now throw a DextinityValidationException, which the global ExceptionFilter turns into a 400 Bad Request.

Example

query {
    product(id: "not-a-uuid") {
        id
    }
}

Before, this failed with invalid input syntax for type uuid: "not-a-uuid".
Now it fails with Invalid UUID 'not-a-uuid' for argument 'id' of ProductResolver::product().

Screenshots

Before After
Before
Before
After

…g the entity

The UserPermissionsGuard runs before pipes, so class-validator decorators
like @IsUUID never see the id args used for the permission check. A
malformed UUID reached PostgreSQL via findOneOrFail and failed with
'invalid input syntax for type uuid', surfacing as an internal server
error instead of a validation error.

Validate id args upfront with isUUID when the affected entity's primary
key is a uuid column (detected via MikroORM metadata, covering both
type: "uuid" and columnType: "uuid" declarations) and for
pageTreeNodeIdArg values, throwing a DextinityValidationException for
malformed values. Entities with non-uuid primary keys are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VP-DS VP-DS self-assigned this Aug 17, 2026
@VP-DS
VP-DS requested a review from VPS-Obi August 17, 2026 07:00
@VP-DS
VP-DS marked this pull request as ready for review August 17, 2026 07:05
@VPS-thodax
VPS-thodax requested a review from fraxachun August 17, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant