Skip to content

fix: harden warehouse SQL identifier quoting - #7249

Closed
achettyiitr wants to merge 18 commits into
masterfrom
fix-harden-warehouse-sql-identifiers
Closed

achettyiitr wants to merge 18 commits into
masterfrom
fix-harden-warehouse-sql-identifiers

Conversation

@achettyiitr

@achettyiitr achettyiitr commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Description

Summary

  • Introduce shared identifier-quoting helpers in warehouse/utils: dialect quoters (double-quote, backtick, bracket), qualified-name and comma-separated joiners, a composite-key splitter (QuoteCommaSeparatedIdentifiers), and a string-literal escaper (SQLStringLiteral). Every quoter escapes by doubling its delimiter — "→"", `→``, ]→]], '→''.
  • Route all warehouse SQL construction through these helpers — Postgres, Redshift, Snowflake, ClickHouse, MSSQL, Azure Synapse, Delta Lake, and BigQuery — replacing raw and %q interpolation of schema, table, column, and staging-table names.
  • Extend coverage beyond DDL to partition keys, dedup/load/users queries, metadata literals, TestLoadTable, and BigQuery view/delete SQL.
  • Split composite partition keys (e.g. the discards row_id, column_name, table_name) into individually quoted columns instead of quoting the whole string as one identifier.
  • Replace interpolation in schemaExists with bind parameters.
  • Leave the datalake schema-repository untouched — it builds schemas via the AWS Glue API / in-memory and constructs no warehouse SQL.

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.

@cursor

cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@achettyiitr
achettyiitr requested a review from krishna2020 August 8, 2026 23:13
@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.61017% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.68%. Comparing base (9e62d0c) to head (7e8cbae).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
warehouse/integrations/snowflake/snowflake.go 84.26% 14 Missing ⚠️
warehouse/integrations/redshift/redshift.go 96.99% 4 Missing ⚠️
...ehouse/integrations/azure-synapse/azure-synapse.go 97.91% 2 Missing ⚠️
warehouse/integrations/mssql/mssql.go 97.87% 2 Missing ⚠️
warehouse/integrations/bigquery/bigquery.go 95.45% 1 Missing ⚠️
warehouse/integrations/clickhouse/clickhouse.go 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7249      +/-   ##
==========================================
- Coverage   80.27%   79.68%   -0.59%     
==========================================
  Files         600      601       +1     
  Lines       67034    67165     +131     
==========================================
- Hits        53811    53521     -290     
- Misses      10070    10467     +397     
- Partials     3153     3177      +24     

☔ 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.

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the fix-harden-warehouse-sql-identifiers branch from 725cb17 to 8cb5416 Compare August 10, 2026 06:29

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.

test cases missing for bigquery

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

BigQuery's CreateTable, AddColumns, and DropTable all go through the typed Go client API (Dataset().Table().Create/Update/Delete) where names are struct fields, not SQL — so those paths are structurally immune to SQL injection, and BQ's API rejects exotic identifier characters outright. The real SQL injection surface in BQ is the raw-SQL paths that interpolate attacker-controlled column names via backtick quoting: the dedup view and the users merge. Adding tests for those.

Comment thread warehouse/utils/utils.go
func DoubleQuoteAndJoinByComma(elems []string) string {
var quotedSlice []string
func DoubleQuoteIdentifier(identifier string) string {
return `"` + strings.ReplaceAll(identifier, `"`, `""`) + `"`

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.

Heads-up: this is a regression for ClickHouse specifically.

ClickHouse applies string-literal escaping rules to double-quoted identifiers, so \ is an escape character there. The fmt.Sprintf("%q", …) this replaces happened to match that convention exactly (" → \", \ → \\), so it was already safe on ClickHouse. Doubling handles " but passes \ through untouched:

column name old %q new
evil\ "evil\\" → identifier evil\ ✅ "evil\" → closing quote is escaped, rest of the column list runs on 💥

Reachable via ColumnsWithDataTypes (clickhouse.go:355, used by CreateTable/CreateSchema) and AddColumns (clickhouse.go:987).

The split is: doubling is correct for Postgres/Redshift/Snowflake/MSSQL/Spark, backslash is correct for ClickHouse and BigQuery — so one shared escaper can't be right for all of them. BacktickQuoteIdentifier has the same mismatch for BigQuery (which escapes as \` rather than by doubling); not a regression there since master interpolated raw, but it leaves the \ breakout open.

Missing test: the cases below only cover the quote character. Worth adding a backslash case:

require.Equal(t, `"evil\\"`, DoubleQuoteIdentifier(`evil\`))       // currently `"evil\"`
require.Equal(t, "`evil\\\\`", BacktickQuoteIdentifier(`evil\`))

…though the assertion depends on which fix you pick (escape \ as \\, or make the helper dialect-specific).

Comment thread warehouse/utils/utils.go
}

func SQLStringLiteral(value string) string {
return `'` + strings.ReplaceAll(value, `'`, `''`) + `'`

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.

Only ' is escaped here, but Snowflake, BigQuery, ClickHouse and Databricks/Spark also honour \ inside string literals — so the doubling can be defeated. An input containing \' becomes \'': the dialect reads \' as a literal quote and the next ' closes the literal, so everything after it is parsed as SQL.

Reachable via operator/config-supplied values at deltalake.go:578 (externalLocation), clickhouse.go:625 (loadFolder), snowflake/table_manager.go:97 (externalVolume), bigquery.go:818.

Doubling alone is correct for Postgres/Redshift/MSSQL/Synapse, so this probably wants to be dialect-specific rather than one shared escaper.

'%[6]s',
'CSV',
'%[7]s',
'%[6]s',

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.

structure is a string literal here, not an identifier list — s3(url, key, secret, format, structure, compression).

sortedColumnNamesWithDataTypes (L588-590) is escaped for identifier position (DoubleQuoteIdentifier doubles "), then interpolated raw between single quotes. Nothing escapes ', so a column named a'b gives:

'CSV', '"a'b" String,…', 'gz'
             ↑ literal ends here

The same helper feeds %[2]s at L605 where identifier quoting is correct — it's only wrong in this slot. %[4]s/%[5]s (accessKeyID/secretAccessKey, L626-627) are raw inside '…' too.

Suggested fix — nest the escaping:

warehouseutils.SQLStringLiteral(sortedColumnNamesWithDataTypes), // 6

Not a regression (master built this fragment unquoted too), just the one interpolation left unhardened inside the statement this hunk hardens. Only fully closed once SQLStringLiteral handles \ as well — see the comment on that helper.

`,
bq.namespace,
fmt.Sprintf(`%s%%`, warehouseutils.StagingTablePrefix(provider)),
warehouseutils.BacktickQuoteQualifiedIdentifier(bq.namespace, "INFORMATION_SCHEMA", "TABLES"),

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.

Worth confirming against a live dataset before merge — I couldn't verify this one statically.

This now emits FROM `ns`.`INFORMATION_SCHEMA`.`TABLES` (same at L818). BigQuery documents the path as dataset.INFORMATION_SCHEMA.VIEW and its examples only backtick the region/project component. If ZetaSQL rejects the per-part quoted form, FetchSchema fails on every BigQuery sync.

Flagging it because nothing here would catch it: bigquery_test.go is untouched by this PR and TestIntegration is gated behind SLOW=1 + real credentials — BigQuery is the only destination in this PR shipping with no test coverage.

Comment thread warehouse/integrations/mssql/mssql.go Outdated
func (ms *MSSQL) createTable(ctx context.Context, tableName string, columns model.TableSchema) (err error) {
tableIdentifier := warehouseutils.BracketQuoteQualifiedIdentifier(ms.namespace, tableName)
sqlStatement := fmt.Sprintf(`IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N%s) AND type = N'U')
CREATE TABLE %s ( %v )`, warehouseutils.SQLStringLiteral(ms.namespace+"."+tableName), tableIdentifier, ColumnsWithDataTypes(columns, ""))

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.

The CREATE TABLE target is now bracket-quoted but the existence guard still uses the raw concatenated name. On master both sides used the same unquoted string so they agreed; now they diverge.

For names that actually need bracket quoting (., ], spaces), OBJECT_ID(N'ns.tbl') returns NULL → IF NOT EXISTS always passes → the CREATE fails with "There is already an object named …".

Same raw-name guard elsewhere:

  • AddColumns L858 (and azure-synapse.go:865) — fails open, so ALTER TABLE … ADD runs on an already-existing column
  • azure-synapse.go:823 — same as here
  • azure-synapse.go:811 dropStagingTable — fails closed, staging table silently leaked

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the fix-harden-warehouse-sql-identifiers branch from 4786d7d to 7e8cbae Compare August 12, 2026 14:02
@krishna2020

Copy link
Copy Markdown
Contributor

Individual warehouse specific PR's will be raised later on

achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: assert that the createTable and
AddColumns existence guards use the same bracket-quoted name as the
statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: assert that the createTable and
AddColumns existence guards use the same bracket-quoted name as the
statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 17, 2026
Address review feedback from #7249: assert that the createTable, AddColumns
and dropStagingTable existence guards use the same bracket-quoted name as
the statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 18, 2026
Address review feedback from #7249: assert that the createTable, AddColumns
and dropStagingTable existence guards use the same bracket-quoted name as
the statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 18, 2026
Address review feedback from #7249: assert that the createTable and
AddColumns existence guards use the same bracket-quoted name as the
statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 18, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 18, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 18, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 23, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 23, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 23, 2026
Address review feedback from #7249: assert that the createTable, AddColumns
and dropStagingTable existence guards use the same bracket-quoted name as
the statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 23, 2026
Address review feedback from #7249: assert that the createTable and
AddColumns existence guards use the same bracket-quoted name as the
statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 23, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
Address review feedback from #7249:
- escape backslash as well as backtick in quoted identifiers, closing the
  trailing-backslash breakout
- bind INFORMATION_SCHEMA filters as query parameters instead of string
  literals, whose escaping differs in GoogleSQL
- extract the users merge SQL into usersMergeQuery and cover it with tests
- drop the unused quoteIdentifiers helper that failed lint

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
Address review feedback from #7249: assert that the createTable, AddColumns
and dropStagingTable existence guards use the same bracket-quoted name as
the statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
Address review feedback from #7249: Spark SQL treats backslash as an
escape character and does not treat a doubled single quote as an escaped
quote, so escape both with a backslash. Also quote the COPY INTO load
folder literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
Address review feedback from #7249: assert that the createTable and
AddColumns existence guards use the same bracket-quoted name as the
statement they protect. Also fix gci import grouping.

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
- DeleteBy quoted lowercase column names, which Snowflake treats as
  case-sensitive and rejects (invalid identifier); apply ToProviderCase
  as before
- escape backslash in string literals and quote EXTERNAL_VOLUME and COPY
  load locations (review feedback from #7249)
- keep the Iceberg BASE_LOCATION path identical to master
- fix gci import grouping

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

🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr added a commit that referenced this pull request Sep 24, 2026
# 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 #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

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
@github-actions
github-actions Bot deleted the fix-harden-warehouse-sql-identifiers branch October 13, 2026 02:09
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.

3 participants