fix(postgresql): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2194
Open
HandSonic wants to merge 4 commits into
Open
fix(postgresql): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2194HandSonic wants to merge 4 commits into
HandSonic wants to merge 4 commits into
Conversation
10 tasks
…r per maintainer review (OtterMind#1914) - PostgreSQLIdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier always double-quotes with embedded-quote doubling, escapeString with single-quote doubling; INSTANCE shared by call sites - PostgreSQLMetaData.getSQLIdentifierProcessor() returns the processor; metadata call sites use it (POSTGRE_SQL_IDENTIFIER_PROCESSOR removed) - builders/managers/enums/templates use PostgreSQLIdentifierProcessor.INSTANCE - non-escapable validation moved to PostgreSqlGuards (pg names, default expressions, bit/hex literals, enum options) - PostgreSqlEscapes removed; tests migrated (38 green)
…-quote for DDL paths (OtterMind#1914) - quoteIdentifier(String) is conditional again: null/blank passthrough, valid non-keyword identifiers returned unquoted, everything else wrapped with embedded-quote doubling; versioned overload delegates to it - quoteIdentifierIgnoreCase is the always-quote SPI variant (preserves case) - new quoteIdentifierAlways(String) for DDL-generation call sites migrated from PostgreSqlEscapes.quoteIdentifier (DBManager, SqlBuilder DDL paths, column/index type enums, MetaData format/getMetaDataName) - buildTableName/buildColumns keep conditional processor quoting - tests cover conditional, always-quote, ignoreCase and null passthrough (40 green)
…oteIdentifier (OtterMind#1914) PostgreSQL folds unquoted identifiers to lowercase, so the conditional quoteIdentifier must quote names containing uppercase (as Oracle/DM do). Found in adversarial confirmation.
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.
Part of the SQL-injection hardening tracked in #1914. Prior art: #2052 (Oracle), #2053 (SQL Server), and the wave-1 batch (#2172-#2177).
These are second-order injection paths: values such as table/schema/view/index names originate from the connected database's own metadata, so exploitation requires a maliciously named object in a target database.
What changed (14 sites)
Promotes the two private quoting statics into a module-level PostgreSqlEscapes and applies them across metadata/DDL paths (MetaData, DBManager DROP DATABASE, SqlBuilder view/schema paths).
Verification
mvn -B -pl chat2db-community-plugins/chat2db-community-postgresql -f chat2db-community-server/pom.xml -Dmaven.test.skip=false -DskipTests=false -Dsurefire.includes=**/*Test.java -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false testResult: Tests run: 38, Failures: 0, Errors: 0, Skipped: 0.
This branch also passed a two-lens adversarial review (escape-correctness/coverage + regression/test-efficacy); all blocking findings were fixed and re-tested before submission.