fix(xugudb): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2175
Open
HandSonic wants to merge 7 commits into
Open
fix(xugudb): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2175HandSonic wants to merge 7 commits into
HandSonic wants to merge 7 commits into
Conversation
…olumn fallback (OtterMind#1914) - Override quoteIdentifier/quoteQualifiedIdentifier/buildSelectTable/buildTableName/ buildColumns in XUGUDBSqlBuilder so inherited DefaultSqlBuilder DQL/DML paths (exportTableData, insert, update) no longer concatenate raw identifiers - Replace raw IColumnBuilder.buildDefaultColumn fallback with escaped name + anchored type-shape validation (reject otherwise) - Return trimmed values from default-value/unit validators - Document raw-identifier contract on XugudbSqlEscapes.escapeIdentifier - Add attack-string tests: malicious schema/table/column via buildSelectTable and buildInsert, comment literal end-to-end, fallback name/type, validator trimming
HandSonic
marked this pull request as draft
July 26, 2026 10:30
… tests (OtterMind#1914) - DEFAULT_VALUE_PATTERN function-call branch now requires balanced single-quoted literals as arguments ('([^']|'')*' allowed, bare quotes rejected), closing the unbalanced-quote gap in default-value validation - Add tests: unbalancedQuoteInFunctionDefaultIsRejected, balancedQuotedArgsInFunctionDefaultAreAccepted - Fix extra closing paren typo in the c3 case
HandSonic
marked this pull request as ready for review
July 26, 2026 11:05
…intainer review (OtterMind#1914) - new XugudbIdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier with double-quote doubling, escapeString with single-quote doubling - XUGUDBMetaData overrides getSQLIdentifierProcessor(); metadata call sites use it - builder/manager/enums use XugudbIdentifierProcessor.INSTANCE - non-escapable validation moved to XugudbSqlGuards (column defaults, length units) - XugudbSqlEscapes removed; tests migrated (21 green)
…rough, conditional for SPI, always for DDL) (OtterMind#1914) Found in re-review: processor was always-quote with null->"" garbage, breaking SPI completion paths; no quoteIdentifierAlways existed.
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.
Related issue
Part of the SQL-injection hardening tracked in #1914 (multi-plugin effort; this PR covers XuguDB). Prior art: #2052 (Oracle
escapeSqlLiteral), #2053 (SQL Server identifier quoting).Summary
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. The fix is still worthwhile hardening and matches the pattern already merged for Oracle and SQL Server.
What changed:
XugudbSqlEscapeshelper:escapeSqlLiteral— neutralizes values interpolated into single-quoted SQL string literals (single-quote doubling).quoteIdentifier/escapeIdentifier— strips one surrounding quote pair and doubles every embedded double quote (") for quoted-identifier positions.SET SCHEMA TO %sandDROP TABLE IF EXISTS %spreviously had no quotes — now quoted + escaped.XUGUDBSqlBuildernow overridesquoteIdentifier/quoteQualifiedIdentifier/buildSelectTable/buildTableName/buildColumnsso inheritedDefaultSqlBuilderDQL/DML paths (exportTableData, insert, update) no longer concatenate raw identifiers.IColumnBuilder.buildDefaultColumnfallback is replaced with an escaped column name plus anchored type-shape validation (reject otherwise). Default-value/unit validators return trimmed values.XugudbSqlEscapesTestcovering literal doubling, identifier doubling, malicious schema/table/column names viabuildSelectTable/buildInsert, comment literals end-to-end, fallback name/type validation, validator trimming, and function-default quote balancing.Affected surfaces
Verification
mvn -B -pl chat2db-community-plugins/chat2db-community-xugudb -f chat2db-community-server/pom.xml -Dmaven.test.skip=false -DskipTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false clean test"is emitted with doubled quotes inside a delimited identifier; invalid column types in the fallback path are rejected withIllegalArgumentException.Risk and compatibility
^...$anchors (a single trailing newline passes as inert whitespace; cosmetic, alignable to\A...\zlater).Reviewer map
XugudbSqlEscapes.java(new helper) andXugudbSqlEscapesTest.java.XUGUDBMetaData/XUGUDBDBManager; the new builder overrides inXUGUDBSqlBuilder; the fallback validation inXUGUDBColumnTypeEnum.Contributor declaration
AI assistance: The fix, verification, and PR description were produced with AI coding assistance.