Skip to content

fix(dm): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2198

Open
HandSonic wants to merge 3 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-dm
Open

fix(dm): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2198
HandSonic wants to merge 3 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-dm

Conversation

@HandSonic

Copy link
Copy Markdown
Contributor

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 (45 sites)

New DMSqlEscapes applied across DMDBManager/DMMetaData/DMSqlBuilder; DEFAULT expressions whitelist-validated (quoted literals/numbers/functions still accepted).

Verification

mvn -B -pl chat2db-community-plugins/chat2db-community-dm -f chat2db-community-server/pom.xml -Dmaven.test.skip=false -DskipTests=false -Dsurefire.includes=**/*Test.java -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false test

Result: Tests run: 11, 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.

… review (OtterMind#1914)

- strengthen DMIdentifierProcessor (SPI ISQLIdentifierProcessor): always-quote
  quoteIdentifier with embedded-quote doubling, escapeString with single-quote
  doubling, static escapeIdentifier for pre-quoted templates, INSTANCE
- DMMetaData.getSQLIdentifierProcessor() returns the shared INSTANCE; metadata
  call sites use it (quoteIdentifier / escapeString / method refs)
- builders/DBManager/enums use DMIdentifierProcessor.INSTANCE / static escapeIdentifier
- non-escapable DEFAULT-expression validation moved to public DMSqlGuards
- DMSqlEscapes removed; tests migrated to DMIdentifierProcessorTest (11 green)
* rejected because DEFAULT values are emitted verbatim.
*/
private static final Pattern DEFAULT_EXPRESSION = Pattern.compile(
"'([^']|'')*'|[+-]?(\\d+(\\.\\d+)?|\\.\\d+)|[A-Za-z_][A-Za-z0-9_]*([.][A-Za-z_][A-Za-z0-9_]*)*(\\s*\\((?:'(?:[^']|'')*'|\\((?:'(?:[^']|'')*'|[^()';])*\\)|[^()';])*\\))?");
* rejected because DEFAULT values are emitted verbatim.
*/
private static final Pattern DEFAULT_EXPRESSION = Pattern.compile(
"'([^']|'')*'|[+-]?(\\d+(\\.\\d+)?|\\.\\d+)|[A-Za-z_][A-Za-z0-9_]*([.][A-Za-z_][A-Za-z0-9_]*)*(\\s*\\((?:'(?:[^']|'')*'|\\((?:'(?:[^']|'')*'|[^()';])*\\)|[^()';])*\\))?");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants