fix(plugin-snowflake): give every statement builder one SQL escaper - #2467
Merged
datlechin merged 1 commit intoAug 26, 2026
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Aug 26, 2026
Merged
Merged
datlechin
added a commit
that referenced
this pull request
Aug 26, 2026
…dpoint sends (#2466) * fix(plugin-snowflake): decode the wire encodings the query-request endpoint sends Claude-Session: https://claude.ai/code/session_01Qk1xfY3vnneRifC22eV2r7 * fix(plugin-snowflake): give every statement builder one SQL escaper (#2467) Claude-Session: https://claude.ai/code/session_01Qk1xfY3vnneRifC22eV2r7 * fix(plugin-snowflake): keep a timestamp offset the date parser cannot represent as text (#2468) Claude-Session: https://claude.ai/code/session_01Qk1xfY3vnneRifC22eV2r7 * fix(plugin-snowflake): take the affected row count from the statement type, not a column name (#2469) Claude-Session: https://claude.ai/code/session_01Qk1xfY3vnneRifC22eV2r7 * fix(plugin-snowflake): key the shared session on the saved connection and scope Stop to its own driver (#2470) Claude-Session: https://claude.ai/code/session_01Qk1xfY3vnneRifC22eV2r7 --------- Co-authored-by: Ngo Quoc Dat <datlechin@gmail.com>
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.
Found while investigating #2454.
The defect
SnowflakeObjectQueries.escapeLiteraldoubled the quote and left the backslash alone:Snowflake reads
\'inside a literal as a content quote, and the driver says so itself:requiresBackslashEscapingInLiteralsistrue. So a schema namedescaped to
x\'' OR 1=1 --. The\'is content, the next'closes the literal,OR 1=1becomes live SQL and--comments the tail. The routine listing then returns every schema's routines.routineDefinitionfeeds the same escaper intoGET_DDL.Schema and routine names arrive from
fetchSchemasunsanitized, so anyone able to create an object in the account controls the string.Why one escaper instead of one fix
Three copies of the literal escaper existed and only one was wrong. Five copies of the identifier quoter existed, all byte identical. Nothing made any of them agree, which is how the wrong one survived.
Writing a fourth correct copy leaves that intact, so
SnowflakeSQLis now the single owner ofescapeLiteral,quoteIdentifierandescapeLikePattern, and every statement builder calls it:SnowflakeObjectQueriesSnowflakeSchemaQueriesSnowflakeDDLGeneratorSnowflakeStatementGeneratorSnowflakeConnectionSnowflakePluginDriverescapeStringLiteralThere is now no hand-rolled quote or backslash doubling anywhere else in the plugin.
SnowflakeObjectQueriesmoved out ofSnowflakePluginDriver+Routines.swiftinto its own file. It is a pure SQL builder that was sharing a file with a driver extension, which is what kept it out of the test target and therefore untested.Order matters
The backslash is doubled before the quotes. Doubling it afterwards would also double the backslashes in the quotes that step just added.
Tests
SnowflakeSQLTests, 11 cases: quote doubling, backslash doubling, escape order, the injection payload above (asserted against what a quote-only escaper produces, so the test states the difference rather than restating the implementation), identifier quoting and an identifier that tries to close its own quoting,LIKEwildcard escaping, and delegation checks pinning that the per-file wrappers stayed wrappers.Verified: build PASS, 56/56 across the escaping suite and every statement-builder suite,
AllPluginscompilesSnowflakeDriverPluginclean, SwiftLint 0 violations.