Skip to content

fix: quote postgres warehouse ddl identifiers - #7127

Merged
achettyiitr merged 12 commits into
masterfrom
harness/INT-6631-fix-quote-postgres-warehouse-dd-8aeacd0d
Jul 14, 2026
Merged

achettyiitr merged 12 commits into
masterfrom
harness/INT-6631-fix-quote-postgres-warehouse-dd-8aeacd0d

Conversation

@rudder-devbox

@rudder-devbox rudder-devbox Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a Postgres warehouse SQL injection path by quoting attacker-controlled identifiers in Postgres DDL and correcting the Postgres Blendo casing sanitizer to truncate the sanitized key instead of the raw input.

Added regressions for malicious column names in transformer output and Postgres ColumnsWithDataTypes / CreateTable SQL generation.

Linear Ticket

INT-6631

Security

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

Validation

  • go test ./processor/internal/transformer/destination_transformer/embedded/warehouse -run 'Test.*(Safe|Transform|Blendo|Column)' - pass
  • go test ./warehouse/integrations/postgres -run 'Test.*ColumnsWithDataTypes|Test.*CreateTable|Test.*Identifier' - pass
  • go test ./processor/internal/transformer/destination_transformer/embedded/warehouse ./warehouse/integrations/postgres - pass
  • Integration verification skipped: rudder-server source is sha-pinned and not source-verifiable in the local mini stack; no services were started.

@rudder-devbox

rudder-devbox Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

👋 I'm rudder-devbox. I opened this PR from a Linear ticket.

Leave an inline comment on the diff — pick a line, add your comment, and
I'll pick it up. No @rudder-devbox mention needed on inline comments; every
inline thread on this PR is something I'll address.

Top-level PR comments need @rudder-devbox. Comment @rudder-devbox <what you want>
on the PR (the top-level conversation, not on a code line) and I'll act on it.
Without the mention I won't see it.

@rudder-devbox

rudder-devbox Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

I found the actionable failure in the ClickHouse integration log: TestIntegration/Events_flow_(single_mode)/No_Partition_Type_specified timed out waiting for warehouse rows after an upload failed with downloading batch: downloading object: making tmp dir: mkdir .../rudder-warehouse-load-objects/users: no such file or directory; the verifier then reported Expected 4 events in WH ... got 0. The Snowflake tests themselves passed (ok github.com/rudderlabs/rudder-server/warehouse/integrations/snowflake), and that job failed later while uploading coverage with Failed to CreateArtifact: Unable to make request: ETIMEDOUT.

I fixed the ClickHouse/root downloader issue by isolating each load-file download under a UUID-scoped temp directory instead of a second-granularity destination directory, preventing concurrent table-load cleanup from removing a shared parent while another download is creating its nested path. I also added a regression asserting downloaded load files do not share the cleanup directory.

Validation passed:

  • go test ./warehouse/internal/service/loadfiles/downloader
  • go test ./processor/internal/transformer/destination_transformer/embedded/warehouse -run 'Test.*(Safe|Transform|Blendo|Column)'
  • go test ./warehouse/integrations/postgres -run 'Test.*ColumnsWithDataTypes|Test.*CreateTable|Test.*Identifier'

Pushed commit: 180a093

@codecov

codecov Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.69%. Comparing base (6c08584) to head (6e34050).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7127      +/-   ##
==========================================
+ Coverage   79.66%   79.69%   +0.03%     
==========================================
  Files         595      595              
  Lines       66134    66140       +6     
==========================================
+ Hits        52684    52713      +29     
+ Misses      10337    10303      -34     
- Partials     3113     3124      +11     

☔ 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-6631-fix-quote-postgres-warehouse-dd-8aeacd0d branch 2 times, most recently from 6e7244c to c2f3b82 Compare July 2, 2026 10:05
@achettyiitr
achettyiitr self-requested a review July 2, 2026 10:09
@achettyiitr
achettyiitr force-pushed the harness/INT-6631-fix-quote-postgres-warehouse-dd-8aeacd0d branch from c2f3b82 to d893eca Compare July 2, 2026 10:17
@achettyiitr
achettyiitr marked this pull request as ready for review July 2, 2026 10:17
@achettyiitr
achettyiitr requested a review from krishna2020 July 2, 2026 10:17
@achettyiitr
achettyiitr changed the base branch from master to release/1.80.x July 8, 2026 06:12
achettyiitr and others added 3 commits July 8, 2026 11:42
## What & why

MAR (Monthly Active Records) metering for reverse-ETL / Audiences
sources produced **no data** in clustered/production deployments:
`activation_records_reports` stayed empty and the MAR API returned `[]`.

The reporter gated reverse-ETL classification on the job's
`source_category` **param**. That param is populated on the gateway
web/auth path, but is **empty on the clustered `/internal/v1/batch`
ingestion path** (rudder-sources → ingestion-svc → Pulsar → srcrouter →
gateway). So every reverse-ETL record was silently skipped — no rows, no
skip stats.

## Change

Classify reverse-ETL (warehouse) sources from the **source config**
(`SourceDefinition.Category`) instead of the job param:

- `processor` snapshots a `source_id → category` map once per batch
(single lock, category strings only) and passes a lookup `func(sourceID
string) string` into the reporter.
- `records_reporter.GenerateReportsFromJobs` gates on that lookup (`==
"warehouse"`), still reading the fingerprint from the raw pre-strip job.

Path-independent (works for `/internal/v1/batch`, `/internal/v1/retl`,
single-node/mini) and fail-closed: an unknown/missing `source_id`
resolves to `""` and is skipped; a spoofed `source_category` param can't
force metering.

This supersedes an earlier gateway-side approach (stamping
`source_category` in the internal-batch handler). Classifying at the
consumer keeps the change contained to the MAR feature and independent
of ingestion topology, and mirrors the sibling tracked-users reporter,
which already takes a source-config lookup.

## Tests

`records_reporter_test.go`: warehouse source metered with an empty
`source_category` param; non-warehouse source skipped; a spoofed
`source_category=warehouse` param does not win over config; unknown
source skipped fail-closed.

## Validation

Verified end-to-end in dev (`profiles-qa`): reverse-ETL sync → rows in
`activation_records_reports` → flushed to the reporting store → MAR API
returns per-connection counts (was `[]`).

Linear: [PRO-5810](https://linear.app/rudderstack/issue/PRO-5810)
🤖 I have created a release *beep* *boop*
---


##
[1.80.1](v1.80.0...v1.80.1)
(2026-07-08)


### Bug Fixes

* classify reverse-ETL sources from config for MAR metering
([#7159](#7159))
([8e026e3](8e026e3))

---
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>
@krishna2020

Copy link
Copy Markdown
Contributor

The identifier quoting added to postgres.go (CreateSchema/CreateTable/AddColumns/DropTable) doesn't extend to load.go, which runs on every upload with the same attacker-influenced pg.Namespace, tableName, and column names.

load.go still interpolates identifiers with %q:

  • load.go:74 — SET search_path TO %q
  • load.go:96 — CREATE TEMPORARY TABLE ... (LIKE %[1]q.%[3]q)
  • load.go:240 / :277 — DELETE/INSERT merge statements
  • load.go:401 — fmt.Sprintf("%q", colName) for user columns

%q is Go string quoting, not Postgres identifier quoting: it escapes " as \", which Postgres does not honor inside a quoted identifier — so the same payload the new tests guard against still breaks out here. Net effect: a table created safely by CreateTable is referenced unsafely by loadTable moments later in the same sync.

Safety on this path currently rests entirely on the upstream safe.go sanitization (the real root-cause fix in this PR). To make the postgres.go hardening consistent, these should move to pq.QuoteIdentifier too — or the DDL-quoting scope should be called out as partial with a follow-up filed. Same applies to postgres.go:282 (DeleteBy) and :313 (namespace interpolated into a string literal, which needs a bind param, not quoting).

Akash Chetty and others added 2 commits July 10, 2026 18:02
🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr requested a review from krishna2020 July 13, 2026 10:49
🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the harness/INT-6631-fix-quote-postgres-warehouse-dd-8aeacd0d branch from a9c24e2 to a8fae9b Compare July 13, 2026 11:21
@rudder-devbox

rudder-devbox Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

The datalake job failed due to external Docker Hub connectivity, not a source-code or test-behavior failure. In TestIntegration/Events_flow, docker compose up could not fetch rudderstack/rudder-transformer:latest: the log reports Get https://auth.docker.io/token ... request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers), followed by Error response from daemon and exit status 1.

The remaining datalake validation tests passed, and the logs contain no assertion, compilation, lint, race, or application error to fix in the repository. No code change or push is appropriate for this transient infrastructure failure; the failed job needs to be rerun when Docker Hub connectivity is available.

@achettyiitr
achettyiitr changed the base branch from release/1.80.x to master July 14, 2026 07:54
@krishna2020

Copy link
Copy Markdown
Contributor

One more that can be addressed in next PR:

In insertIntoLoadTable, the column list still uses warehouseutils.DoubleQuoteAndJoinByComma(sortedColumnKeys), which wraps names with fmt.Sprintf("%q", elem):

// warehouse/utils/utils.go:598
quotedSlice = append(quotedSlice, fmt.Sprintf("%q", elem))

@rudder-devbox

rudder-devbox Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

CI failed before the test could run: TestConnectionPoolCookieIsolation reported manifest ... rudder-pytransformer:pr-112 not found while starting its container. The branch had inherited a stale temporary image tag, so I restored the contract test to the published rudder-pytransformer:main image and pushed the fix. git diff --check passes; the local compile-only test was stopped while downloading the repository's large dependency set.

6e34050

@achettyiitr
achettyiitr merged commit 5aeb481 into master Jul 14, 2026
73 of 74 checks passed
@achettyiitr
achettyiitr deleted the harness/INT-6631-fix-quote-postgres-warehouse-dd-8aeacd0d branch July 14, 2026 09:14
This was referenced Jul 20, 2026
mihir20 pushed a commit that referenced this pull request Jul 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.81.0-rc.1](v1.80.0...v1.81.0-rc.1)
(2026-07-20)


### Features

* run python transformation tests on ephemeral per-request pyt
deployments
([#7177](#7177))
([1008ae7](1008ae7))
* support partition migration job fanout per jobsdb
([#7141](#7141))
([be42e48](be42e48))


### Bug Fixes

* abort snowpipe events on channel bad request
([#7118](#7118))
([6c08584](6c08584))
* avoid redundant transformer statTags unmarshalling
([#7182](#7182))
([c3c283c](c3c283c))
* classify reverse-ETL sources from config for MAR metering
([#7159](#7159))
([fa7870f](fa7870f))
* detect server-side snowpipe channel failures via per-channel status at
stuck threshold
([#7166](#7166))
([581410c](581410c))
* kafkamanager compilation error
([#7189](#7189))
([1fb7f6e](1fb7f6e))
* **kafka:** support insecure TLS skip verify config
([#7022](#7022))
([d01574f](d01574f))
* preserve order when overflowing snowpipe insert batches
([#7178](#7178))
([9c01fa0](9c01fa0))
* quote postgres warehouse ddl identifiers
([#7127](#7127))
([5aeb481](5aeb481))
* **router:** emit invalid payload metric
([#7168](#7168))
([6e2009a](6e2009a))
* update null to #N/A for salesforce bulk upload
([#7151](#7151))
([1dffd93](1dffd93))
* **warehouse:** use pod identity for rudder-storage flow; keep S3-copy
user fallback for user S3 destinations
([#7167](#7167))
([3f9aa32](3f9aa32))


### Miscellaneous

* add contract tests for test endpoints in pytransformer
([#7147](#7147))
([3b210ec](3b210ec))
* bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815
([#7162](#7162))
([7672f96](7672f96))
* **deps:** bump actions/checkout from 6.0.3 to 7.0.0
([#7132](#7132))
([d453c93](d453c93))
* **deps:** bump actions/setup-go from 6.4.0 to 6.5.0
([#7150](#7150))
([75d9648](75d9648))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6
([#7109](#7109))
([7b2a859](7b2a859))
* **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to
6.2.2 ([#7152](#7152))
([c984268](c984268))
* **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0
([#7170](#7170))
([4565d25](4565d25))
* **deps:** bump the frequent group across 1 directory with 4 updates
([#6891](#6891))
([88a0ddf](88a0ddf))
* support compression in bqstream destinations
([#7142](#7142))
([0694f12](0694f12))

---
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>
mihir20 pushed a commit that referenced this pull request Jul 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.81.0](v1.80.0...v1.81.0)
(2026-07-20)


### Features

* run python transformation tests on ephemeral per-request pyt
deployments
([#7177](#7177))
([1008ae7](1008ae7))
* support partition migration job fanout per jobsdb
([#7141](#7141))
([be42e48](be42e48))


### Bug Fixes

* abort snowpipe events on channel bad request
([#7118](#7118))
([6c08584](6c08584))
* avoid redundant transformer statTags unmarshalling
([#7182](#7182))
([c3c283c](c3c283c))
* classify reverse-ETL sources from config for MAR metering
([#7159](#7159))
([fa7870f](fa7870f))
* detect server-side snowpipe channel failures via per-channel status at
stuck threshold
([#7166](#7166))
([581410c](581410c))
* kafkamanager compilation error
([#7189](#7189))
([1fb7f6e](1fb7f6e))
* **kafka:** support insecure TLS skip verify config
([#7022](#7022))
([d01574f](d01574f))
* preserve order when overflowing snowpipe insert batches
([#7178](#7178))
([9c01fa0](9c01fa0))
* quote postgres warehouse ddl identifiers
([#7127](#7127))
([5aeb481](5aeb481))
* **router:** emit invalid payload metric
([#7168](#7168))
([6e2009a](6e2009a))
* update null to #N/A for salesforce bulk upload
([#7151](#7151))
([1dffd93](1dffd93))
* **warehouse:** use pod identity for rudder-storage flow; keep S3-copy
user fallback for user S3 destinations
([#7167](#7167))
([3f9aa32](3f9aa32))


### Miscellaneous

* add contract tests for test endpoints in pytransformer
([#7147](#7147))
([3b210ec](3b210ec))
* bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815
([#7162](#7162))
([7672f96](7672f96))
* **deps:** bump actions/checkout from 6.0.3 to 7.0.0
([#7132](#7132))
([d453c93](d453c93))
* **deps:** bump actions/setup-go from 6.4.0 to 6.5.0
([#7150](#7150))
([75d9648](75d9648))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6
([#7109](#7109))
([7b2a859](7b2a859))
* **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to
6.2.2 ([#7152](#7152))
([c984268](c984268))
* **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0
([#7170](#7170))
([4565d25](4565d25))
* **deps:** bump the frequent group across 1 directory with 4 updates
([#6891](#6891))
([88a0ddf](88a0ddf))
* support compression in bqstream destinations
([#7142](#7142))
([0694f12](0694f12))

---
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>
achettyiitr added a commit that referenced this pull request Sep 17, 2026
insertIntoLoadTable built the column list with DoubleQuoteAndJoinByComma,
which uses Go's %q and escapes a double quote as \" instead of doubling it,
so a column name containing a quote could break out of the identifier. Quote
each column with pq.QuoteIdentifier instead. Raised as a follow-up on #7127.

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
insertIntoLoadTable built the column list with DoubleQuoteAndJoinByComma,
which uses Go's %q and escapes a double quote as \" instead of doubling it,
so a column name containing a quote could break out of the identifier. Quote
each column with pq.QuoteIdentifier instead. Raised as a follow-up on #7127.

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
insertIntoLoadTable built the column list with DoubleQuoteAndJoinByComma,
which uses Go's %q and escapes a double quote as \" instead of doubling it,
so a column name containing a quote could break out of the identifier. Quote
each column with pq.QuoteIdentifier instead. Raised as a follow-up on #7127.

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
insertIntoLoadTable built the column list with DoubleQuoteAndJoinByComma,
which uses Go's %q and escapes a double quote as \" instead of doubling it,
so a column name containing a quote could break out of the identifier. Quote
each column with pq.QuoteIdentifier instead. Raised as a follow-up on #7127.

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
…ence check (#7405)

# Description

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

Most Postgres identifiers in generated DDL and load SQL are already
quoted with `DoubleQuoteIdentifier`. Two gaps remained:

1. `schemaExists` interpolated the namespace into a `'…'` string
literal:

```sql
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = '<namespace>');
```

This PR passes the namespace as a bind parameter (`$1`) instead, so a
namespace containing `'` can no longer break out of the literal.

2. `insertIntoLoadTable` built the column list with
`warehouseutils.DoubleQuoteAndJoinByComma`, which uses Go's `%q`. Go
escapes a double quote as `\"`, which Postgres does not honour inside a
quoted identifier, so a column name containing `"` could break out. Each
column is now quoted with `DoubleQuoteIdentifier` (follow-up raised on
#7127).

## Tests

- Integration test `TestIntegration` → `Load Table` → "prevents SQL
injection via malicious identifiers" (replaces "quotes identifiers in
create table" and the sqlmock-based create-table quoting test): creates
a namespace containing `'` and `"` breakout payloads and runs
`CreateSchema` twice (the second call must find the existing schema,
which fails if the namespace is interpolated into a string literal),
then creates a table and columns whose names contain `"` breakout
payloads (plus a trailing-backslash column) alongside a control table.
It then verifies the control table survives, `AddColumns` works on the
malicious table, 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.
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.

4 participants