Repository navigation
🔒 fix(sink/postgres): harden DSN/host redaction (SEC-01-FUP1/FUP2) - #182
Merged
Merged
Conversation
SEC-01 (PR #174) redacted the DSN/host from pgx ParseConfig failures. Two operator-approved follow-ups close the remaining latent gaps. FUP1 — delete the dead backtick-strip fallback in redactedParseError. It was a latent fail-open: for any non-*pgconn.ParseConfigError it echoed the pgx reason (including the raw host) after the quoted DSN. That branch is unreachable in pinned pgx v5.10.0 — pgxpool.ParseConfig routes every fault through *pgconn.ParseConfigError (pgx.ParseConfig for connection-string faults; pgconn.NewParseConfigError for every pool-param fault) — but a future pgx bump could reintroduce a non-PCE leaking path. redactedParseError now fails closed with the static message unconditionally. FUP2 — redact post-parse dial errors. pgxpool.NewWithConfig connects lazily (verified: it returns a live pool + nil even with pool_min_conns=1), so the dial fault surfaces via pool.Ping (connection.go) and the ensureTable Exec (backend.go), NOT via newGuardedPool's return. pgx wraps it in *pgconn.ConnectError whose text embeds the tenant user, database, and — via the wrapped perDialConnectError and the netguard resolver echo — the target host. New redactedConnectError returns a static message for that type while keeping the error non-nil (callers still see the failure); non-connect errors pass through unchanged. Wired into both surfacing sites. Runtime-query Exec leaks (bulk_export.go, backend.go upsert path) are a separate, larger surface and left as a follow-up. Tests: extended pool_test.go (RED before fix) — FUP1 synthesizes a non-PCE backtick-echoing error and asserts the static message; FUP2 drives a real *pgconn.ConnectError through the netguard path (127.0.0.1:1, blocked before egress) and asserts no user/database/host tokens leak, via the helper and end-to-end through TestConnection and NewBackend.
There was a problem hiding this comment.
Pull request overview
This PR follows up on SEC-01 by hardening PostgreSQL error redaction so DSN/host/user/db details cannot leak via pgx error strings, covering both DSN parse failures and post-parse dial/connect failures.
Changes:
- Removes the previously “fail-open” fallback path in
redactedParseError, making it always fail closed with a static message. - Introduces
redactedConnectErrorto redact*pgconn.ConnectError(lazy-connect/dial failures) and wires it into the two surfacing call sites. - Extends
pool_test.gowith unit and end-to-end tests to ensure sensitive tokens do not appear in returned error strings.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/sink/postgres/pool.go | Removes leaky parse-error fallback; adds connect-error redaction helper. |
| internal/sink/postgres/pool_test.go | Adds regression tests for fail-closed parse redaction and dial/connect redaction, plus end-to-end coverage. |
| internal/sink/postgres/connection.go | Applies connect-error redaction to pool.Ping failure path. |
| internal/sink/postgres/backend.go | Applies connect-error redaction to ensureTable failure path during backend construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+34
to
+36
| // colon). We therefore return a STATIC message and never fold any of its | ||
| // free-form text back in — the typed error's ConnString/Unwrap remain available | ||
| // programmatically but never hit the returned string. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.



Summary
Two operator-approved follow-ups to SEC-01 (PR #174), which redacted the DSN/host from pgx
ParseConfigfailures viaredactedParseError. Both touchinternal/sink/postgres/pool.go, so they land in one lane.FUP1 (P3) — delete the dead backtick-strip fallback
redactedParseErrorhad a fallback that, for any non-*pgconn.ParseConfigError, echoed the pgx reason (including the raw host) after the quoted DSN — a latent fail-open. Verified unreachable in pinned pgx v5.10.0:pgxpool.ParseConfigroutes every fault through*pgconn.ParseConfigError(pgx.ParseConfigfor connection-string faults;pgconn.NewParseConfigErrorfor every pool-param fault). A future pgx bump could reintroduce a non-PCE leaking path, so the function now fails closed with the static message unconditionally.FUP2 (P3) — redact post-parse dial errors
pgxpool.NewWithConfigconnects lazily (verified: returns a live pool +nileven withpool_min_conns=1), so a dial fault does not surface vianewGuardedPool's return — it surfaces on first use:pool.Ping(connection.go) and theensureTableExec (backend.go). pgx wraps it in*pgconn.ConnectError, whose text embeds the tenant user, database, and — through the wrappedperDialConnectErrorand the netguard resolver echo — the target host. NewredactedConnectErrorreturns a static message for that type while keeping the error non-nil (callers still see the failure); non-connect errors pass through unchanged. Wired into both surfacing sites.TDD (RED → GREEN)
Extended
internal/sink/postgres/pool_test.go; all assertions confirmed RED before the fix:secret-db.internal).*pgconn.ConnectErrorthrough the netguard dial path (127.0.0.1:1, rejected as non-routable before any egress — hermetic, instant) and asserts nouser/database/hosttokens leak. Covered at the helper level and end-to-end throughTestConnectionandNewBackend; plus a pass-through test for non-connect errors.Gate matrix (all green)
go build ./...— passgo vet ./...— passtask lint— 0 issues, arch-lint OKtask verify— passtask test/task coverage— all packages ok, internal/ coverage 85.7% (floor 85%)Follow-up (out of scope)
Runtime-query
Execleaks (bulk_export.go,backend.goupsert path) are a separate, larger surface — noted for a later lane.