Repository navigation
fix: validate the query and WITH list of INSERT, UPDATE, DELETE and MERGE - #2937
Merged
manticore-projects merged 1 commit intoNov 18, 2026
Conversation
Contributor
|
Thank you! |
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.
InsertValidatorvalidates the source query of anINSERTonly when it is aVALUESlist. ForINSERT ... SELECTit reportsFeature.insertFromSelectand stops there, so nothing inside the query reachesSelectValidatoror anyValidationCapability. WithFeaturesAllowed.INSERT.copy().remove(Feature.function),INSERT INTO t VALUES (pg_read_file('/etc/passwd'))reportsfunction not allowed.butINSERT INTO t SELECT pg_read_file('/etc/passwd')validates with no errors, andINSERT INTO t SELECT a FROM s FOR UPDATEpassesFeaturesAllowed.INSERTalthoughselectForUpdateis not part of it. None of the four DML validators look at theWITHlist either, soWITH d AS (DELETE FROM s RETURNING a) INSERT INTO t SELECT a FROM dpassesFeaturesAllowed.INSERT, the same CTE passesUPDATEandMERGE, and anUPDATE ... RETURNINGCTE passesDELETE, while PostgreSQL executes the data-modifying CTE in every one of them. It showed up while checking the DML validators after #2928, which closed the same kind of gap forTABLEandVALUESbut did not touchInsertValidator,UpdateValidator,DeleteValidatororMergeValidator. A non-VALUESsource query is now walked withSelectValidatorthe wayUpsertValidatoralready does it, and theWITHitems go through a smallvalidateOptionalWithItemshelper inAbstractValidator. The new cases inInsertValidatorTest,UpdateValidatorTest,DeleteValidatorTestandMergeValidatorTestfail before and pass after, andPostgresqlVersion.V14still accepts the statements. Locally./gradlew testshows the same 35 failures with and without the change (Mockito inline mock maker and file permissions in my sandbox, none of them in validation), and Spotless, Checkstyle, PMD and SpotBugs pass.