cms-api: Validate UUID format of AffectedEntity id args before loading the entity - #6207
Open
VP-DS wants to merge 2 commits into
Open
cms-api: Validate UUID format of AffectedEntity id args before loading the entity#6207VP-DS wants to merge 2 commits into
VP-DS wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@AffectedEntity()loads the affected entity inUserPermissionsGuardto 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 throughfindOneOrFail(), which failed withinvalid input syntax for type uuid(22P02). Instead of a validation error, the client got an internal server error.Solution
Validate the id arguments in
ContentScopeServicebefore the entity is loaded:idArgvalues are checked withisUUID()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.pageTreeNodeIdArgvalues are checked as well, as they were exposed to the same failure inpageTreeApi.getNode().Malformed ids now throw a
DextinityValidationException, which the globalExceptionFilterturns into a400 Bad Request.Example
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