Skip to content

fix(warehouse): quote redshift identifiers - #7365

Merged
achettyiitr merged 13 commits into
masterfrom
harness/INT-6791-quote-redshift-identifiers
Sep 24, 2026
Merged

achettyiitr merged 13 commits into
masterfrom
harness/INT-6791-quote-redshift-identifiers

Conversation

@rudder-devbox

@rudder-devbox rudder-devbox Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to master once it merges.

Redshift SQL statements were built with Go's %q or raw "…" interpolation of schema, table, staging-table and column names. %q produces Go string escaping (\"), not SQL escaping, so a name containing " was not safely quoted.

This PR routes all generated SQL through the shared quoting helpers added in #7406 (warehouse/utils/identifier.go): DoubleQuoteIdentifier, DoubleQuoteQualifiedIdentifier, DoubleQuoteAndJoinByComma and QuoteCommaSeparatedIdentifiers, and routes all generated SQL through them:

  • CreateTable (columns and SORTKEY), DropTable, AddColumns, createSchema
  • DeleteBy, staging-table creation and cleanup (including dangling staging tables)
  • COPY targets and column lists, dedup DELETE … USING and INSERT … row_number() (composite discards partition keys are split into individually quoted columns)
  • loadUserTables (FIRST_VALUE projections, union/staging tables, merge delete/insert)
  • AlterColumn (add/update/rename/drop column statements) and TestLoadTable

schemaExists now passes the namespace as a bind parameter instead of interpolating it.

The S3 source location in the COPY statements (load files and TestLoadTable) is emitted through SQLStringLiteralBackslash, which escapes both ' and \ because Redshift interprets backslash escape sequences inside string literals.

Redshift folds quoted identifiers to lowercase by default, so quoting existing names does not change which objects are resolved.

Tests

  • Integration test TestIntegration → Load Table → "prevents SQL injection via malicious identifiers": creates a namespace, table and columns whose names contain " breakout payloads, alongside a control table, then verifies the control table survives, the names round-trip verbatim through FetchSchema, and DropTable drops only the targeted table.
  • redshift_injection_test.go (DDL-drop and COPY … TO PROGRAM payloads): column-list quoting neutralizes identifier breakout payloads.

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
achettyiitr force-pushed the harness/INT-6791-quote-redshift-identifiers branch 2 times, most recently from 8e9c887 to 2bf64f5 Compare September 17, 2026 11:15
@achettyiitr
achettyiitr marked this pull request as ready for review September 17, 2026 12:15
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.14286% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.51%. Comparing base (ec0cf52) to head (547f00a).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
warehouse/integrations/redshift/redshift.go 97.14% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7365      +/-   ##
==========================================
+ Coverage   83.79%   84.51%   +0.72%     
==========================================
  Files         622      622              
  Lines       61979    62045      +66     
==========================================
+ Hits        51936    52439     +503     
+ Misses      10040     9603     -437     
  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.

@achettyiitr
achettyiitr force-pushed the harness/INT-6791-quote-redshift-identifiers branch from 38a0f49 to 5c3a6b8 Compare September 18, 2026 04:29
@achettyiitr
achettyiitr changed the base branch from master to feature/int-6791-warehouse-identifier-utils September 18, 2026 04:29
achettyiitr added a commit that referenced this pull request Sep 23, 2026
… helpers (#7406)

# Description

The warehouse integrations each build SQL from schema, table and column
names that originate from event payloads. Quoting those names correctly
is dialect specific, and the rules were about to be duplicated in every
integration package.

This PR adds them once in `warehouse/utils/identifier.go`:

**Identifiers**

| Helper | Dialect | Escaping |
| --- | --- | --- |
| `DoubleQuoteIdentifier` | Postgres, Redshift, Snowflake | `"` doubled
|
| `BracketQuoteIdentifier` | MSSQL, Azure Synapse | `]` doubled |
| `BacktickQuoteIdentifier` | Databricks (Spark SQL) | `` ` `` doubled |
| `BigQueryQuoteIdentifier` | BigQuery (GoogleSQL) | `` ` `` and `\`
backslash escaped |

`QuoteQualifiedIdentifier`, `JoinQuotedIdentifiers` and
`QuoteCommaSeparatedIdentifiers` take the dialect's quoting function, so
composite partition keys and column lists are quoted per column.
`BigQueryQuoteTablePath` quotes a dotted `project.dataset.table` path as
a single identifier.

**String literals**

| Helper | Dialect | Escaping |
| --- | --- | --- |
| `SQLStringLiteral` / `UnicodeStringLiteral` | MSSQL, Azure Synapse |
`'` doubled, `N'…'` variant |
| `SQLStringLiteralBackslash` | Redshift, Snowflake | `\` escaped, `'`
doubled |
| `SparkSQLStringLiteral` | Databricks | `\` escaped, `'` escaped as
`\'` |

Redshift, Snowflake, BigQuery and Databricks all interpret backslash
escape sequences inside string literals, so doubling the quote alone can
be defeated by a value containing `\'`.

This PR only adds the helpers. The integration PRs stacked on it switch
their SQL over:

- #7363 (Azure Synapse)
- #7364 (MSSQL)
- #7365 (Redshift)
- #7366 (BigQuery)
- #7367 (Snowflake)
- #7368 (Deltalake)
- #7405 (Postgres)

## Tests

- `identifier_test.go`: per dialect identifier escaping (including
breakout payloads and a trailing backslash), qualified identifiers,
identifier lists, comma separated column lists, and the three string
literal forms. Each escaper is also run over a value containing every
delimiter and escape character (`"`, `` ` ``, `]`, `'`, `\`) to assert
it escapes only its own.

## 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.
Base automatically changed from feature/int-6791-warehouse-identifier-utils to master September 23, 2026 06:45
@achettyiitr
achettyiitr force-pushed the harness/INT-6791-quote-redshift-identifiers branch from 5c3a6b8 to 6708d97 Compare September 23, 2026 11:40
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.
rudder-devbox and others added 11 commits September 24, 2026 11:03
Add a live integration test that creates a schema, table and columns whose
names carry SQL injection payloads alongside a control table, and asserts the
control table survives, the malicious names round-trip verbatim through
FetchSchema and DropTable only drops the targeted table. Also add a unit test
asserting column-list quoting neutralizes identifier breakout payloads.

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

🔒 Scanned for secrets using gitleaks 8.29.1
The S3 location in the COPY statements for load files and TestLoadTable was
interpolated into '...' without escaping. Escape it as a string literal,
handling backslashes as well as single quotes since Redshift interprets
backslash escape sequences inside string literals.

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

🔒 Scanned for secrets using gitleaks 8.29.1
Run the identifier and string literal escapers over a value containing every
delimiter and escape character (" ` ] ' \) to assert the dialect escapes
only its own delimiters and handles backslashes correctly.

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

🔒 Scanned for secrets using gitleaks 8.29.1
Replace the package local quoting helpers with the shared ones from
warehouse/utils so the escaping rules live in one place. The generated SQL is
unchanged; the escaping is covered by the helper tests.

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

🔒 Scanned for secrets using gitleaks 8.29.1
Rename the quoted main table variable to mainTableName and build the discards
join references with DoubleQuoteQualifiedIdentifier instead of concatenating
the qualified table with the column. The generated SQL is unchanged.

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

🔒 Scanned for secrets using gitleaks 8.29.1
The shared Redshift test user has been unlocked, so drop the skip added while
every run failed with "pq: Account locked due to multiple failed login
attempts". The SLOW=1 and credential guards are unchanged, so this PR's
identifier tests now run against Redshift again.

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
Move the quoting test into the package and name it
<integration>_quoting_internal_test.go, 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
DoubleQuoteAndJoinByComma only forwards to JoinQuotedIdentifiers, so pass the
dialect's quote function at the call site instead.

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

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the harness/INT-6791-quote-redshift-identifiers branch from 527bdff to e45b033 Compare September 24, 2026 05:41
…edaction working

REGION was still hand quoted while the location beside it moved to the escaping
helper. The redaction patterns also matched [^'] inside each credential literal,
so a quote in a secret would end the match early and leave the rest in the log.

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

🔒 Scanned for secrets using gitleaks 8.29.1
…on that created it

A schema is owned by whichever identity created it, so the schema the IAM role
validation creates cannot be dropped by the password user. The cleanup retried for
a minute and failed every attempt with permission denied for schema, which is the
only thing still failing in this suite. Open the connection from the destination
under test instead.

Also cover the COPY region escaping and the credential masking. The earlier change
made the masking patterns follow a doubled quote, which does nothing here: the
credentials are interpolated without escaping, so a quote in one appears singly and
ends the match exactly as before. Revert that part and say so, rather than implying
a protection that is not there. The masking map is now shared between the middleware
and the load test instead of being declared twice.

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

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr merged commit a3e2a3c into master Sep 24, 2026
73 checks passed
@achettyiitr
achettyiitr deleted the harness/INT-6791-quote-redshift-identifiers branch September 24, 2026 11:35
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.

3 participants