Skip to content

fix(warehouse): quote clickhouse identifiers - #7420

Merged
achettyiitr merged 6 commits into
masterfrom
fix/int-6791-quote-clickhouse-identifiers
Sep 24, 2026
Merged

achettyiitr merged 6 commits into
masterfrom
fix/int-6791-quote-clickhouse-identifiers

Conversation

@achettyiitr

Copy link
Copy Markdown
Member

Description

ClickHouse was deliberately left out of the per-integration identifier quoting work until the v2 driver landed. Now that v1 is gone and v2 is the only implementation, this applies the same treatment.

ClickHouse SQL was built by interpolating database, table and column names with Go's %q, and by embedding the load folder, credentials and the s3() structure argument in raw '…' literals. %q is Go string quoting rather than SQL quoting, and nothing escaped the values placed inside the string literals.

Helpers (warehouse/utils/identifier.go): ClickHouseQuoteIdentifier, ClickHouseQuoteQualifiedIdentifier and ClickHouseQuoteAndJoinByComma. ClickHouse applies string-literal escape rules inside double-quoted identifiers, so the delimiter and the backslash are escaped with a backslash rather than doubled — unlike Postgres, Redshift and Snowflake. String literals reuse SQLStringLiteralBackslash, which escapes \ and '.

Statements routed through them:

  • CreateSchema (CREATE DATABASE), ON CLUSTER, and CREATE TABLE for both the ReplacingMergeTree and AggregatingMergeTree paths
  • column definitions (ColumnsWithDataTypes) and the ORDER BY sort key tuple
  • AddColumns (ALTER TABLE … ADD COLUMN), DropTable, and the row count query
  • both INSERT paths, including the one that previously used DoubleQuoteAndJoinByComma, which doubles the quote and is therefore wrong for ClickHouse
  • the s3() copy statement: the column list is quoted, and the load folder, credentials and the structure argument are escaped as string literals. The structure argument is a string literal holding column definitions, so its identifiers are quoted first and the whole value is then escaped — the nesting fix: harden warehouse SQL identifier quoting #7249 called out.

The partition expression still uses the internal received_at constant unquoted, so the generated PARTITION BY is unchanged.

Tests

  • clickhouse_quoting_internal_test.go: column definitions neutralize breakout payloads, including a trailing backslash, which a doubling escaper would get wrong; and the s3() copy statement quotes its column list and escapes the folder, credentials and structure argument.
  • warehouse/utils/identifier_test.go: ClickHouse identifier, qualified identifier and comma-joined list escaping, including the all-delimiters value used by the other dialects.
  • Integration test TestIntegration → "prevents SQL injection via malicious identifiers": creates a database, table and columns whose names carry " breakout payloads (plus a trailing-backslash column) alongside a control table, then verifies the control table survives, the names round-trip verbatim through FetchSchema, and DropTable drops only the targeted table.

Linear Ticket

Resolves INT-6791

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

achettyiitr added a commit that referenced this pull request Sep 24, 2026
…#7421)

# Description

`warehouse/utils` grew both a generic and a per dialect way to build the
same SQL:

```go
QuoteQualifiedIdentifier(DoubleQuoteIdentifier, ns, table)   // generic
DoubleQuoteQualifiedIdentifier(ns, table)                    // wrapper
```

The wrappers only restate the generic helper with the quoting function
filled in, so this removes them:

- `DoubleQuoteQualifiedIdentifier`, `BracketQuoteQualifiedIdentifier`,
`BacktickQuoteQualifiedIdentifier`
- `BracketQuoteAndJoinByComma`, `BacktickQuoteAndJoinByComma`

Callers pass the dialect's quoting function to
`QuoteQualifiedIdentifier` or `JoinQuotedIdentifiers` instead, which is
how `QuoteCommaSeparatedIdentifiers` already works.

What stays:

- the dialect escapers (`DoubleQuoteIdentifier`,
`BracketQuoteIdentifier`, `BacktickQuoteIdentifier`,
`BigQueryQuoteIdentifier`), which is where the dialects genuinely differ
- `BigQueryQuoteTablePath`, which quotes a dotted path as one identifier
rather than part by part, so it is not the generic helper with an
argument filled in
- `DoubleQuoteAndJoinByComma`, which predates this work and is used
across the warehouse integrations

Nothing on master used the removed wrappers; the INT-6791 integration
PRs (#7363, #7364, #7365, #7366, #7367, #7368, #7405, #7420) have been
updated to call the generic helpers, so they are unaffected whichever
order these merge in.

## Tests

- `identifier_test.go`: the dialect assertions now go through
`QuoteQualifiedIdentifier` and `JoinQuotedIdentifiers`, covering the
same escaping.

## Linear Ticket

Related to INT-6791

## Security

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
ClickHouse SQL was built by interpolating database, table and column names with
Go's %q and embedding the load folder, credentials and the s3 structure argument
in raw string literals. %q is Go string quoting, and while it happens to match
ClickHouse escaping for the quote character, nothing escaped the values inside
the string literals.

Add ClickHouse quoting helpers to warehouse/utils, which escape the delimiter and
the backslash with a backslash because ClickHouse applies string literal escape
rules inside quoted identifiers, and route the generated SQL through them:
CREATE DATABASE, CREATE TABLE for both engines, the sort key tuple, column
definitions, ALTER TABLE ADD COLUMN, DROP TABLE, ON CLUSTER, the row count query
and both INSERT paths. The s3 copy statement now quotes its column list and
escapes the load folder, credentials and structure argument as string literals.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
Use <integration>_quoting_internal_test.go for in-package tests and
<integration>_quoting_test.go for external ones, matching the other
integrations.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
Build qualified identifiers and identifier lists with QuoteQualifiedIdentifier
and JoinQuotedIdentifiers, passing the dialect's quoting function, instead of
per dialect wrappers. The generated SQL is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
The subtest talked to the manager as soon as the container started, so the first
statement could hit a server that was not accepting connections yet. Use the
same readiness ping the other subtests use.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
ClickHouseQuoteIdentifier now lives in warehouse/utils on master, so drop the
copy this branch carried.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the fix/int-6791-quote-clickhouse-identifiers branch from 34dbfda to 5b0a094 Compare September 24, 2026 05:40
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.76%. Comparing base (ec0cf52) to head (5542c34).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
warehouse/integrations/clickhouse/clickhouse.go 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7420      +/-   ##
==========================================
- Coverage   83.79%   83.76%   -0.03%     
==========================================
  Files         622      622              
  Lines       61979    61974       -5     
==========================================
- Hits        51936    51915      -21     
- Misses      10040    10056      +16     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…oted secrets

The masking pattern matched [^'] inside each literal, so it stopped at the first
doubled quote and left the access key, secret and session token in the log once
the copy crossed the slow query threshold. A MinIO secret access key is customer
supplied and may contain a quote, so follow a doubled quote instead.

Also assert the structure argument is escaped on both layers, and point the
driver test at the column list the code now builds.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr merged commit 490c097 into master Sep 24, 2026
111 of 113 checks passed
@achettyiitr
achettyiitr deleted the fix/int-6791-quote-clickhouse-identifiers branch September 24, 2026 10:25
This was referenced Sep 28, 2026
itsmihir pushed a commit that referenced this pull request Sep 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.89.0-rc.1](v1.88.0...v1.89.0-rc.1)
(2026-09-28)


### Features

* **warehouse:** add shared SQL identifier and string literal quoting
helpers
([#7406](#7406))
([814f6db](814f6db))


### Bug Fixes

* **warehouse:** quote azure synapse identifiers
([#7363](#7363))
([d399fd1](d399fd1))
* **warehouse:** quote bigquery identifiers
([#7366](#7366))
([89de526](89de526))
* **warehouse:** quote clickhouse identifiers
([#7420](#7420))
([490c097](490c097))
* **warehouse:** quote deltalake identifiers
([#7368](#7368))
([08f2f1e](08f2f1e))
* **warehouse:** quote mssql identifiers
([#7364](#7364))
([695b881](695b881))
* **warehouse:** quote postgres load column list and bind schema
existence check
([#7405](#7405))
([2ff81c1](2ff81c1))
* **warehouse:** quote redshift identifiers
([#7365](#7365))
([a3e2a3c](a3e2a3c))
* **warehouse:** quote snowflake identifiers
([#7367](#7367))
([53d4891](53d4891))


### Miscellaneous

* sync release v1.88.0 to main branch
([#7415](#7415))
([130bdd3](130bdd3))
* **warehouse:** drop the per dialect identifier quoting wrappers
([#7421](#7421))
([ec0cf52](ec0cf52))
* **warehouse:** drop the v2 suffix now v1 is gone
([#7418](#7418))
([b759c33](b759c33))
* **warehouse:** move back to upstream clickhouse-go
([#7419](#7419))
([1a7e776](1a7e776))
* **warehouse:** remove the ClickHouse v1 driver
([#7417](#7417))
([bd14179](bd14179))
* **warehouse:** replace dead clickhouse blockSize with commitEvery
([#7427](#7427))
([0806478](0806478))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Sep 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.89.0](v1.88.0...v1.89.0)
(2026-09-28)


### Features

* **warehouse:** add shared SQL identifier and string literal quoting
helpers
([#7406](#7406))
([814f6db](814f6db))


### Bug Fixes

* **warehouse:** quote azure synapse identifiers
([#7363](#7363))
([d399fd1](d399fd1))
* **warehouse:** quote bigquery identifiers
([#7366](#7366))
([89de526](89de526))
* **warehouse:** quote clickhouse identifiers
([#7420](#7420))
([490c097](490c097))
* **warehouse:** quote deltalake identifiers
([#7368](#7368))
([08f2f1e](08f2f1e))
* **warehouse:** quote mssql identifiers
([#7364](#7364))
([695b881](695b881))
* **warehouse:** quote postgres load column list and bind schema
existence check
([#7405](#7405))
([2ff81c1](2ff81c1))
* **warehouse:** quote redshift identifiers
([#7365](#7365))
([a3e2a3c](a3e2a3c))
* **warehouse:** quote snowflake identifiers
([#7367](#7367))
([53d4891](53d4891))


### Miscellaneous

* sync release v1.88.0 to main branch
([#7415](#7415))
([130bdd3](130bdd3))
* **warehouse:** drop the per dialect identifier quoting wrappers
([#7421](#7421))
([ec0cf52](ec0cf52))
* **warehouse:** drop the v2 suffix now v1 is gone
([#7418](#7418))
([b759c33](b759c33))
* **warehouse:** move back to upstream clickhouse-go
([#7419](#7419))
([1a7e776](1a7e776))
* **warehouse:** remove the ClickHouse v1 driver
([#7417](#7417))
([bd14179](bd14179))
* **warehouse:** replace dead clickhouse blockSize with commitEvery
([#7427](#7427))
([0806478](0806478))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants