[Cherry-pick to branch-1.3] [#11839] fix(clickhouse): escape single quotes in database and table name SQL to prevent injection (#11840)#11895
Open
github-actions[bot] wants to merge 1 commit into
Conversation
…name SQL to prevent injection (#11840) ### What changes were proposed in this pull request? - Override `generateDatabaseExistSql` in `ClickHouseDatabaseOperations` to query `system.databases` with proper single-quote escaping via `escapeSingleQuotes`. The inherited default targets `information_schema.SCHEMATA` which ClickHouse does not support. - Escape `databaseName` and `tableName` in `ClickHouseTableOperations.getIndexes()` before interpolating into `QUERY_INDEXES_SQL`. - Add unit tests for `generateDatabaseExistSql` covering normal names and names containing single quotes. ### Why are the changes needed? Both code paths interpolate user-provided names into SQL string literals without escaping single quotes, creating SQL injection vulnerabilities. ClickHouse's JDBC driver does not support `PreparedStatement` parameterization for `system`-table queries, so string escaping (single-quote doubling) is the correct and only viable mitigation. The fix reuses the existing `ClickHouseClusterUtils.escapeSingleQuotes()` utility already used by `generateCreateDatabaseSql`, `generateAlterTableSql`, and other methods in the same module. Fix: #11839 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - `./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:spotlessApply` — passes - `./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:build` — passes - `./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test` — all tests pass, including new tests: - `testGenerateDatabaseExistSqlNormalName` — verifies normal name produces correct SQL - `testGenerateDatabaseExistSqlSingleQuoteEscaped` — verifies `test'db` → `test''db`
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.
Cherry-pick Information:
branch-1.3