Skip to content

fix(snowflake): escape SQL identifiers and literals in metadata/DDL paths (#1914) - #2200

Merged
openai0229 merged 4 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-snowflake
Jul 29, 2026
Merged

fix(snowflake): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2200
openai0229 merged 4 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-snowflake

Conversation

@HandSonic

@HandSonic HandSonic commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #1914

Summary

Completes the Snowflake database-plugin portion of the identifier and literal escaping work.

  • Adds a Snowflake identifier processor with conditional SPI quoting, unconditional DDL quoting, case folding, reserved-word handling, embedded-quote escaping, and exact quote/remove round trips.
  • Routes metadata, manager, builder, column-type, and index-type SQL generation through the processor.
  • Adds closed guards for default expressions, column types, index definitions, clustering clauses, sort orders, and other non-escapable SQL fragments.
  • Preserves inherited DML behavior while covering Snowflake-specific metadata and DDL paths.
  • Expands regression coverage for case folding, reserved words, boundary quotes, unknown types, defaults, indexes, clustering clauses, and adversarial metadata names.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • mvn -pl chat2db-community-plugins/chat2db-community-snowflake -am clean test -Dmaven.test.skip=false -DskipTests=false
    • Result: BUILD SUCCESS across 9 reactor modules; 797 tests passed in tested modules, including Snowflake 28/28, MySQL 653/653, SPI 90/90, and tools 26/26.
    • git diff --check origin/main...HEAD: passed.
  • Manual verification: Source-level generated-SQL review completed. No live Snowflake instance was used.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: No public API or stored-data schema change. Implements the existing shared ISQLIdentifierProcessor contract.
  • Database or driver compatibility: Snowflake case folding and reserved words now determine conditional quoting; metadata and DDL paths retain exact names through unconditional quoting.
  • Network, privacy, or security: No network or privacy change. Reduces malformed SQL and identifier/literal injection risk in generated Snowflake SQL.
  • Community / Local / Pro boundary: Community Snowflake plugin only; Local and Pro consume the Community plugin behavior without product-specific code changes.
  • Backward compatibility: Existing valid unquoted identifiers and supported SQL expressions remain accepted; malformed or ambiguous raw fragments now fail closed.

Reviewer map

  • Start here: SnowflakeIdentifierProcessor, SnowflakeSqlGuards, and SnowflakeIdentifierProcessorTest, then review metadata and builder call sites.
  • Failure condition: quote/remove loses raw identifier text, case folding changes identity, generated SQL exposes metadata outside identifier or literal boundaries, or legal Snowflake defaults/types/cluster clauses stop rendering.
  • Rollback or disable path: Revert this PR; no migration or persisted-data rollback is required.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: Substantial AI-assisted maintainer revision and test expansion; all final changes were source-reviewed and verified with the commands above.

HandSonic and others added 4 commits July 29, 2026 19:30
…per maintainer review (OtterMind#1914)

- new SnowflakeIdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier
  with double-quote doubling, escapeString with single-quote doubling
- SnowflakeMetaData overrides getSQLIdentifierProcessor(); metadata call sites use it
- builder/enums/DBManager use SnowflakeIdentifierProcessor.INSTANCE
- non-escapable validation moved to SnowflakeSqlGuards (name tokens, default
  expressions, index sort direction); USE SCHEMA keeps unquoted+whitelist schema
- SnowflakeSqlEscapes removed; tests migrated (19 green)
Preserve identifier round trips and Snowflake case folding, quote inherited DML builder paths, and validate raw defaults, custom types, index metadata, and clustering clauses.

Co-authored-by: HandSonic <8078023+handsonic@users.noreply.github.com>
@openai0229
openai0229 force-pushed the fix/sqli2-snowflake branch from 6f6ba1f to 11b4f5f Compare July 29, 2026 11:32

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on the latest main and verified the complete Snowflake identifier/literal handling path. The clean 9-module reactor passes, including Snowflake 28/28, MySQL 653/653, SPI 90/90, and tools 26/26.

@openai0229
openai0229 merged commit 8431346 into OtterMind:main Jul 29, 2026
19 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Security: 34 SQL Injection Vulnerabilities in Database Plugins

2 participants