Repository navigation
fix(router): redact credentials from destination URLs in failure responses - #7372
Conversation
…onses A destination URL routinely authenticates in its query string (?api_key=..., ?access_token=...) and occasionally in userinfo. Every message this package composes for a failed request embeds that URL, and those messages are not internal: they become the job's error response, which the failed-records feature stores verbatim in a table in the customer's own warehouse and renders in the UI, where it outlives the request by the configured retention. redactURLCredentials keeps scheme, host and path - a failed-records row exists to say which destination rejected the data - and drops query, fragment and userinfo, marking that it did so. It runs over the composed message rather than the URL alone because the URL arrives by two routes: the explicit interpolation, and again inside the error, since net/http returns *url.Error whose Error() repeats the request URL. That second copy carries the query parameters appended after postInfo.URL is read, so it is not even the same string; redacting the inputs separately would leave it behind. An unparseable URL is withheld rather than passed through: this function cannot show such a string is credential-free, and these values reach a customer's warehouse. The precedent is enterprise/reporting/error_extractor.go, which deletes URLs from error messages outright before reporting aggregates them.
…e sites The 400 construction failure, the 504 request failure and the response-body read failure each interpolate postInfo.URL into the body they return. The network tests now assert through SendPost itself that a credential in the destination's query string does not reach the response body, so deleting a redaction call fails them rather than silently reopening the leak.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7372 +/- ##
==========================================
+ Coverage 79.93% 79.95% +0.01%
==========================================
Files 619 620 +1
Lines 69465 69492 +27
==========================================
+ Hits 55528 55559 +31
+ Misses 10688 10686 -2
+ Partials 3249 3247 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // It stops at whitespace and at the quote characters the router's own messages wrap | ||
| // URLs in, so a %q-quoted URL is matched without swallowing the closing quote, and a | ||
| // URL at the end of a sentence keeps its trailing punctuation outside the match. | ||
| var urlInText = regexp.MustCompile(`https?://[^\s"'` + "`" + `<>]+`) |
There was a problem hiding this comment.
Should we make the regex configurable list so that we can add more cases later if we discover some new case in the future?
There was a problem hiding this comment.
Good question, and it turned out to point at a real gap — though I'd argue against config as the mechanism. Pushed 4e24649.
Why not configurable. This regex isn't a denylist of secrets, it's a URL finder: the actual redaction is url.Parse + drop query/fragment/userinfo. So making it configurable wouldn't let us add new kinds of secret, only change what counts as a URL — which is structural (RFC 3986) rather than policy that evolves. And it's a security control whose failure mode is a customer's API key landing in their own warehouse: a typo'd or non-compiling regex would either panic at boot or silently stop redacting, which cuts against the fail-closed design elsewhere in the file (an unparseable URL is withheld, not passed through), and nothing would test the configured value. The nearest precedent agrees — enterprise/reporting/error_extractor.go hardcodes all six of its redaction regexes (url, ip, email, …) while making the error-message keys and length limit configurable. Structure hardcoded, policy configurable. Repo-wide it's 0 config-driven regexes against ~80 hardcoded ones.
But you were right that cases were missing. I probed a destination URL configured without a scheme and it leaked:
in: api.example.com/v1/events?api_key=s3cr3t
out: 400 ... for URL : "api.example.com/v1/events?api_key=s3cr3t" ← unchanged
https?:// doesn't match it. http.NewRequest happily accepts such a URL, the failure surfaces later from Do, and the credential reached the body through the error's own copy of the URL.
Fix: pattern matching is now the backstop, not the mechanism. Where we hold the URL we redact it with url.Parse (which reads a scheme-less URL as path + query, so it works regardless of shape); where we hold the error we replace the URL that *url.Error repeats by substring, so an error wrapped further out keeps its text and the cause reads unchanged. redactURL is idempotent, so the regex pass over the composed message can't double-mark what those already handled. Both passes are mutation-checked independently through SendPost — dropping either fails the scheme-less case.
That also answers your underlying worry better than a config list would, since it no longer depends on recognising the shape at all. If we later find secrets arriving in genuinely non-URL forms (a token echoed in a destination's own response body, say), that needs a different mechanism — a key denylist or entropy check — and it belongs on the capture path in services/rsources so it covers destination-supplied text too. Happy to file that separately if you think it's worth having.
Review raised whether the URL-matching regex should be configurable so new cases could be added later. The regex is a URL finder rather than a policy list, so configuring it would only change what counts as a URL - but the concern was right that cases were missing, and probing found one: a destination configured without a scheme is not an "https://" match, so its query string survived. http.NewRequest accepts such a URL, the failure surfaces later from Do, and the credential reached the response body through the error's own copy of it. Pattern matching is now the backstop rather than the mechanism. Where the caller holds the URL it is redacted with url.Parse, which reads a scheme-less URL as a path plus query; where the caller holds the error, the URL that *url.Error repeats is replaced by substring, so an error wrapped further out keeps its text and the cause reads unchanged. redactURL is idempotent, so the backstop over the composed message cannot double-mark what those passes already handled. Both passes are independently mutation-checked through SendPost: dropping either one fails the scheme-less case.
atzoum
left a comment
There was a problem hiding this comment.
Should we redact URLs coming back from the transformer proxy too? SendPost isn't
called when transformerProxy is on (worker.go:523), so that path is untouched.
Review caught that the comment claiming the match left trailing punctuation alone was false, and it was: a URL ending a sentence took the period with it, and a comma between clauses disappeared from the message. Sentence-ending punctuation is now excluded from the last character of a match. Square and curly brackets are deliberately not in that set. The redaction marker ends in ']', so excluding it would truncate an already-redacted URL and append a second marker - which the idempotency test caught. Comments trimmed to what each function does; the threat model they described lives in the PR description.
|
@atzoum on the transformer-proxy question — you're right that the path is untouched, but I traced it and I don't think there's a credential of this class to redact there. Proposing we leave this PR's scope as is; details so you can check my reasoning: With What is exposed on that path is the transformer's response body, relayed verbatim — and if the transformer echoes the destination URL it called, a credential can ride along in there. That's destination-supplied text rather than something we compose, so no compose-site fix reaches it; it needs scrubbing where the text is captured. Same mechanism @mihir20's question points at for secrets that aren't URLs at all. So I'd rather not stretch this PR to cover it, and instead file one follow-up for capture-path scrubbing in Also pushed 45b9276 for your three inline comments: the punctuation claim was indeed false (the match was eating commas and periods out of the message) so that's fixed rather than just reworded, and the comments are trimmed to what the code does. |
@kuldeep0020 this look like a pure llm-generated response... |
Proposal: leave this PR as is, and I raise a separate ticket for the proxy path. The proxy path has no URL of ours to redact. The only one we put into an error there is the transformer's own endpoint: It can still leak, but through text we don't compose: If you'd rather that go in this PR, tell me and I'll add it here. |
atzoum
left a comment
There was a problem hiding this comment.
@kuldeep0020 my main question is how we plan to handle transformer proxy responses. I’m specifically concerned about transformer proxy because it’s our component, and it may be including the external URL in its error responses.
If the plan is to handle URL redaction generically inside the rsources package, that would mean applying redaction across all scenarios. That wouldn’t necessarily be a bad thing, but it would be a fundamentally different approach.
In that case, if we are indeed planning to introduce such a generic mechanism, I’m not sure why we need the current PR, since it takes a different and much more targeted approach.
Finally, if we do go with a generic handler, I don’t think a regex-only solution would be sufficient. Running regex matching against every error string can be relatively expensive, and I’m not sure that’s a cost we want to pay for every single error response.
Did some more investigation in transformer proxy's code and currently there is no scenario where it can include the external url in its error responses. Let's rule out this scenario for now and focus on the rest 👍 |
atzoum
left a comment
There was a problem hiding this comment.
Please simplify the description and avoid private links, since this is a public repository.
What we’re doing here is simply redacting URL information from router error messages by retaining only the scheme, host, and path. This prevents any potential credentials or other sensitive information in query parameters from being logged or included in RETL failed records.
IMO, the Verification and Deliberately out of scope sections are unnecessary as well.
🤖 I have created a release *beep* *boop* --- ## [1.87.0-rc.1](v1.86.0...v1.87.0-rc.1) (2026-09-14) ### Features * backend config shadow mode ([#7340](#7340)) ([4898165](4898165)) * bump rudder-go-kit and go modules to Go 1.27.1 ([#7345](#7345)) ([8d95c68](8d95c68)) * **router:** read transformerProxy from transformer features before env ([#7337](#7337)) ([e8f0ea6](e8f0ea6)) ### Bug Fixes * **router:** redact credentials from destination URLs in failure responses ([#7372](#7372)) ([14659bf](14659bf)) * **warehouse:** instrument the clickhouse v2 load path ([#7355](#7355)) ([4d743db](4d743db)) * **warehouse:** pass temporary credentials to the clickhouse v2 s3 copy engine ([#7353](#7353)) ([4d743db](4d743db)) * **warehouse:** retire idle clickhouse v2 connections ([#7352](#7352)) ([4d743db](4d743db)) * **warehouse:** retry a failed clickhouse v2 block ([#7354](#7354)) ([4d743db](4d743db)) ### Miscellaneous * **processor:** assemble side-PU report metrics at end of preprocess stage ([#7346](#7346)) ([4540876](4540876)) * sync release v1.86.0 to main branch ([#7356](#7356)) ([6868c6c](6868c6c)) --- 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>
🤖 I have created a release *beep* *boop* --- ## [1.87.0-rc.2](v1.86.0...v1.87.0-rc.2) (2026-09-14) ### Features * backend config shadow mode ([#7340](#7340)) ([4898165](4898165)) * bump rudder-go-kit and go modules to Go 1.27.1 ([#7345](#7345)) ([8d95c68](8d95c68)) * **router:** read transformerProxy from transformer features before env ([#7337](#7337)) ([e8f0ea6](e8f0ea6)) ### Bug Fixes * **router:** redact credentials from destination URLs in failure responses ([#7372](#7372)) ([14659bf](14659bf)) * **warehouse:** instrument the clickhouse v2 load path ([#7355](#7355)) ([4d743db](4d743db)) * **warehouse:** pass temporary credentials to the clickhouse v2 s3 copy engine ([#7353](#7353)) ([4d743db](4d743db)) * **warehouse:** retire idle clickhouse v2 connections ([#7352](#7352)) ([4d743db](4d743db)) * **warehouse:** retry a failed clickhouse v2 block ([#7354](#7354)) ([4d743db](4d743db)) ### Miscellaneous * log the candidate error when a backend config shadow sample fails to fetch ([#7383](#7383)) ([eaa9b61](eaa9b61)) * **processor:** assemble side-PU report metrics at end of preprocess stage ([#7346](#7346)) ([4540876](4540876)) * sync release v1.86.0 to main branch ([#7356](#7356)) ([6868c6c](6868c6c)) --- 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>
🤖 I have created a release *beep* *boop* --- ## [1.87.0-rc.3](v1.86.0...v1.87.0-rc.3) (2026-09-14) ### Features * backend config shadow mode ([#7340](#7340)) ([4898165](4898165)) * bump rudder-go-kit and go modules to Go 1.27.1 ([#7345](#7345)) ([8d95c68](8d95c68)) * **router:** read transformerProxy from transformer features before env ([#7337](#7337)) ([e8f0ea6](e8f0ea6)) ### Bug Fixes * **router:** redact credentials from destination URLs in failure responses ([#7372](#7372)) ([14659bf](14659bf)) * **router:** request fails with unexpected use of stub RoundTripper error ([#7386](#7386)) ([2ff491f](2ff491f)) * **warehouse:** instrument the clickhouse v2 load path ([#7355](#7355)) ([4d743db](4d743db)) * **warehouse:** pass temporary credentials to the clickhouse v2 s3 copy engine ([#7353](#7353)) ([4d743db](4d743db)) * **warehouse:** retire idle clickhouse v2 connections ([#7352](#7352)) ([4d743db](4d743db)) * **warehouse:** retry a failed clickhouse v2 block ([#7354](#7354)) ([4d743db](4d743db)) ### Miscellaneous * log the candidate error when a backend config shadow sample fails to fetch ([#7383](#7383)) ([eaa9b61](eaa9b61)) * **processor:** assemble side-PU report metrics at end of preprocess stage ([#7346](#7346)) ([4540876](4540876)) * sync release v1.86.0 to main branch ([#7356](#7356)) ([6868c6c](6868c6c)) --- 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>
🤖 I have created a release *beep* *boop* --- ## [1.87.0-rc.4](v1.86.0...v1.87.0-rc.4) (2026-09-15) ### Features * backend config shadow mode ([#7340](#7340)) ([4898165](4898165)) * bump rudder-go-kit and go modules to Go 1.27.1 ([#7345](#7345)) ([8d95c68](8d95c68)) * **router:** read transformerProxy from transformer features before env ([#7337](#7337)) ([e8f0ea6](e8f0ea6)) ### Bug Fixes * **batchrouter:** retry failed async manager initialization ([#7374](#7374)) ([974d383](974d383)) * **router:** redact credentials from destination URLs in failure responses ([#7372](#7372)) ([14659bf](14659bf)) * **router:** request fails with unexpected use of stub RoundTripper error ([#7386](#7386)) ([2ff491f](2ff491f)) * singer-protocol sources filtered destination config for source type cloud instead of cloudSource ([#7389](#7389)) ([f48c997](f48c997)) * **warehouse:** instrument the clickhouse v2 load path ([#7355](#7355)) ([4d743db](4d743db)) * **warehouse:** pass temporary credentials to the clickhouse v2 s3 copy engine ([#7353](#7353)) ([4d743db](4d743db)) * **warehouse:** retire idle clickhouse v2 connections ([#7352](#7352)) ([4d743db](4d743db)) * **warehouse:** retry a failed clickhouse v2 block ([#7354](#7354)) ([4d743db](4d743db)) ### Miscellaneous * log the candidate error when a backend config shadow sample fails to fetch ([#7383](#7383)) ([eaa9b61](eaa9b61)) * **processor:** assemble side-PU report metrics at end of preprocess stage ([#7346](#7346)) ([4540876](4540876)) * sync release v1.86.0 to main branch ([#7356](#7356)) ([6868c6c](6868c6c)) --- 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>
🤖 I have created a release *beep* *boop* --- ## [1.87.0](v1.86.0...v1.87.0) (2026-09-15) ### Features * backend config shadow mode ([#7340](#7340)) ([4898165](4898165)) * bump rudder-go-kit and go modules to Go 1.27.1 ([#7345](#7345)) ([8d95c68](8d95c68)) * **router:** read transformerProxy from transformer features before env ([#7337](#7337)) ([e8f0ea6](e8f0ea6)) ### Bug Fixes * **batchrouter:** retry failed async manager initialization ([#7374](#7374)) ([974d383](974d383)) * **router:** redact credentials from destination URLs in failure responses ([#7372](#7372)) ([14659bf](14659bf)) * **router:** request fails with unexpected use of stub RoundTripper error ([#7386](#7386)) ([2ff491f](2ff491f)) * singer-protocol sources filtered destination config for source type cloud instead of cloudSource ([#7389](#7389)) ([f48c997](f48c997)) * **warehouse:** instrument the clickhouse v2 load path ([#7355](#7355)) ([4d743db](4d743db)) * **warehouse:** pass temporary credentials to the clickhouse v2 s3 copy engine ([#7353](#7353)) ([4d743db](4d743db)) * **warehouse:** retire idle clickhouse v2 connections ([#7352](#7352)) ([4d743db](4d743db)) * **warehouse:** retry a failed clickhouse v2 block ([#7354](#7354)) ([4d743db](4d743db)) ### Miscellaneous * log the candidate error when a backend config shadow sample fails to fetch ([#7383](#7383)) ([eaa9b61](eaa9b61)) * **processor:** assemble side-PU report metrics at end of preprocess stage ([#7346](#7346)) ([4540876](4540876)) * sync release v1.86.0 to main branch ([#7356](#7356)) ([6868c6c](6868c6c)) --- 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>
Closes the B1 blocker from @arpl's architects-panel review on rudder-specs#109 (review 5007342017, 24 Aug,
CHANGES_REQUESTED). It was the last item from that review still outstanding, deferred as "the wave after the Aris discussion".Problem
router/network.gocomposes its own error text for a failed request and embeds the destination URL. Three sites do it:Destination URLs routinely authenticate in the query string (
?api_key=…,?access_token=…) and occasionally in userinfo. That text becomes the job'sResponseBody, and nothing downstream removes it — the only sanitisation on the failed-keys capture path issanitizeErrorText, whose own doc says what it is for: "makes the captured text safe to store in a postgres text column" — strip NULs, fix invalid UTF-8. Storability, not safety.Why this matters now. These strings used to reach logs and reporting. With the failed-records feature they are persisted verbatim into a table in the customer's own warehouse, rendered in the UI, and kept for
retentionInDays(default 30, and the spec permits 3650). The first connection that opts in is the first chance to write a customer's live API key into their own warehouse.The org already treats this as something to strip —
enterprise/reporting/error_extractor.goremoves whole URLs from error messages before reporting aggregates them. The reporting pipeline redacts; the failed-keys pipeline did not.Fix
redactURLCredentialskeeps scheme, host and path and drops query, fragment and userinfo, leaving a visible?[redacted]marker so an operator can tell "this endpoint takes no parameters" from "its parameters were withheld". Keeping the endpoint is deliberate: a failed-records row exists to tell someone which destination rejected their data, andhttps://api.example.com/v1/eventsanswers that where a blank does not. That is the one place this diverges from the reporting extractor, which wipes the URL entirely.It runs over the composed message, not the URL alone — which is the subtlety worth reviewing. The URL reaches the text by two routes: the explicit interpolation, and again inside
%v, becausenet/httpreturns*url.ErrorfromDoand itsError()is%s %q: %sover Op, URL and cause. That second copy is the request URL after the query parameters this package appends at:215-221, so it is not even the same string as the interpolated one. Redacting the inputs separately leaves it behind.TestRedactURLCredentialsCoversTheWrappedErrorpins exactly this: it asserts the unredacted message contains the secret twice, then that neither copy survives.Unparseable input is withheld (
[redacted url]) rather than passed through — this function cannot show such a string is credential-free, and the value is headed for a customer's warehouse.Verification
TestRedactURLCredentials; removing the redaction call from the 504 site failsTestSendPost/should_not_leak_destination_credentials_in_the_failure_response. The wiring is asserted throughSendPostitself, not just against the helper, so an unwired site cannot pass.network_test.goexpectations are unaffected — they assert on the message prefix, which is unchanged.gofmt,go vet, andgolangci-lint v2.9.0(the Makefile pin) over./router/...: 0 issues.TestRouterIsolation,TestEventOrderGuarantee,Test_RouterThrottling,TestThrottlePerEventType) could not run in my sandbox — no network to pull images (lookup registry-1.docker.io: no such host). They are untouched by this change; CI covers them.Deliberately out of scope
network.goalso logs the raw URL vialogger.NewStringField("url", postInfo.URL)at:205and:258. That is an internal exposure with different handling, and changing log output would break greps; worth a separate decision.