Skip to content

Reference upstream by id (not URL) in connector error messages#244

Merged
artemrootman merged 6 commits into
mainfrom
fix/redact-upstream-url-in-errors
Jul 18, 2026
Merged

Reference upstream by id (not URL) in connector error messages#244
artemrootman merged 6 commits into
mainfrom
fix/redact-upstream-url-in-errors

Conversation

@artemrootman

@artemrootman artemrootman commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

When an upstream request fails at the connection layer (DNS failure, connection refused/reset, TLS error, timeout), http.Client.Do returns a *url.Error whose Error() embeds the full upstream URL — both any credential carried in its path/query (e.g. /v2/<key>, ?dkey=<key>) and the host itself. HttpConnector wrapped that raw error verbatim into the client-facing ResponseError, so the URL could surface to the caller. The ctx-cancelled branches and the "invalid upstream url" client-failure paths leaked it the same way.

Fix

Tag each HttpConnector with the id of the upstream it serves (threaded through the connector factory), and make every connector failure path reference the upstream by id only:

  • upstream <id> request failed
  • unable to read response from upstream <id>
  • invalid url for upstream <id>
  • ctx-cancelled: upstream <id>: context canceled

The full URL is still logged for operators (zerolog), but never returned to the caller.

Tests

A connector test drives a connection failure and asserts the client-facing error references the upstream id while neither the API key nor the host survives in it.

HttpConnector wrapped the raw *url.Error from failed upstream requests
into the client-facing ResponseError. That string embeds the full upstream
URL - both any credential in its path/query (e.g. /v2/<key>, ?dkey=<key>)
and the host itself, which is infrastructure disclosure. The ctx-cancelled
branches and the "invalid upstream url" client-failure paths leaked it too.

Tag each HttpConnector with its upstream id (threaded through the factory)
and make every connector failure path reference the upstream by id only.
The full URL is logged for operators (zerolog) but never returned to the
caller. Covered by a connector test that fails if the key OR the host
survives in the client-facing error.
@mxssl
mxssl requested a review from KirillPamPam July 11, 2026 19:26
Comment thread internal/upstreams/upstream_factory.go Outdated
return newHttpConnectorWithId(connectorConfig, specs.RestConnector, torProxyUrl, upId)
case specs.RestAdditional:
return connectors.NewHttpConnector(connectorConfig, specs.RestAdditional, torProxyUrl)
return newHttpConnectorWithId(connectorConfig, specs.RestAdditional, torProxyUrl, upId)

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.

Maybe just add up id to NewHttpConnector ?

Drop the WithUpstreamId builder method and the newHttpConnectorWithId
factory helper; both constructors now take upstreamId directly.
@artemrootman
artemrootman merged commit 423a359 into main Jul 18, 2026
5 checks passed
@artemrootman
artemrootman deleted the fix/redact-upstream-url-in-errors branch July 18, 2026 15:47
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.

2 participants