Skip to content

[http] Hide URL passwords in error messages, and use it for proxy_url - #1478

Closed
manugarg wants to merge 2 commits into
mainfrom
http-strip-proxy-url-credentials
Closed

manugarg wants to merge 2 commits into
mainfrom
http-strip-proxy-url-credentials

Conversation

@manugarg

@manugarg manugarg commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

net/http replaces a URL's password with *** before putting it in an error.
net/url does not — url.Parse embeds the string it was handed, password and
all. So a URL we parse but never fetch keeps its credentials all the way into
the log.

proxy_url is the case that hits: the message included the URL twice, once from
the config value and once from url.Parse.

before: error parsing proxy URL (http://user:[email protected]:notaport/):
          parse "http://user:[email protected]:notaport/": invalid port ":notaport" after host

after:  parse "http://user:***@proxy.example.com:notaport/": invalid port ":notaport" after host

Change

Rather than a one-off, this teaches the existing helper from #1410/#1477 to hide
passwords alongside queries, so redactErrMsg now makes any URL in a message
safe to log — and proxy_url just calls it. The reason and the rest of the URL
survive, which the earlier version of this PR lost by dropping the error
entirely.

It works on the raw string, because the URL that reaches us is often one
url.Parse rejected, and it leaves a bare username alone — that isn't the
secret.

Testing

TestStripURLPassword covers userinfo, bare username, @ in the path, a port
mistaken for a password, and unparseable URLs.
TestProxyURLParseErrorHidesPassword asserts the password is gone while
invalid port and the host remain.

go build ./..., go vet, go test -race ./probes/http/..., gofmt clean.

@manugarg
manugarg force-pushed the http-strip-proxy-url-credentials branch from 5f791fb to 587aee4 Compare September 9, 2026 00:45
@manugarg manugarg changed the title [http] Keep proxy credentials out of the proxy_url parse error [http] Don't put proxy_url in its parse error Sep 9, 2026
net/http replaces a URL's password with *** before putting it in an
error; net/url does not -- url.Parse embeds the string it was handed,
password and all. So a URL we parse but never fetch keeps its
credentials all the way into the log.

Hide the password in redactErrMsg alongside the query, so one helper
makes any URL in a message safe to log. It works on the raw string
because the URL that reaches us is often one Parse rejected, and it
leaves a bare username alone -- that is not the secret.
The message included the proxy URL twice -- once from the config value,
once from url.Parse, which embeds the string it was handed -- so a proxy
URL with credentials logged the password.

Now that redactErrMsg hides passwords, the generic helper covers this:
the message keeps the reason and the rest of the URL, and only the
password goes.

    before: error parsing proxy URL (http://user:hunter2@proxy:notaport/):
            parse "http://user:hunter2@proxy:notaport/": invalid port ...
    after:  parse "http://user:***@proxy:notaport/": invalid port ...
@manugarg
manugarg force-pushed the http-strip-proxy-url-credentials branch from 587aee4 to 8163b56 Compare September 9, 2026 01:07
@manugarg manugarg changed the title [http] Don't put proxy_url in its parse error [http] Hide URL passwords in error messages, and use it for proxy_url Sep 9, 2026
@manugarg manugarg closed this Sep 9, 2026
@manugarg
manugarg deleted the http-strip-proxy-url-credentials branch September 16, 2026 01:04
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.

1 participant