Repository navigation
Added an option to opt out of logging query parameters - #1410
Conversation
|
This mostly LGTM. I'll take a deeper look soon. |
There was a problem hiding this comment.
Single-run/RunOnce leaks the query: doHTTPRequest returns the raw err (a *url.Error with the full URL), which eventually gets printed unredacted. Suggest returning a redacted error (e.g. errors.New(p.redactedErr(req.URL, err))) at http.go:342/354.
Worth gating the rewrap on the flag, so the default path keeps the typed error:
if p.redactURLQueryInLogs {
return errors.New(p.redactedErr(req.URL, err))
}
return errRewrapping unconditionally is safe today -- isClientTimeout does its *url.Error assertion at http.go:334, before the return, and nothing downstream of runProbe type-asserts on this error -- but leaving err untouched when the option is off keeps the "default false, existing behavior unchanged" contract exact.
manugarg
left a comment
There was a problem hiding this comment.
http.go:602 leaks the same way in single-run mode -- httpRequestForTarget's error is logged verbatim and also passed to LastRun.Set. With relative_url: "/login?password=secret\x7f" it produces:
error creating HTTP request: parse "http://t1/login?password=secret\x7f": net/url: invalid control character in URL
Worth covering in the same pass.
…some http probes can contain sensitive data in query parameters
Redaction matched the full rendered URL against one log message, which missed the cases that matter in practice: - After a redirect, net/http builds its *url.Error from the last request it made, so the URL in the error is the redirect target's, and the full-URL match finds nothing. HTTP->HTTPS upgrade redirects carry the query over, so this is the common shape rather than a corner case. - url.Error renders the URL with %q, so a query containing a quote or a backslash arrives escaped and doesn't match its plain form. - doHTTPRequest redacted only what it logged and returned the raw error, which --run-once and the probe-run RPC print verbatim. - Request construction failures and Init's relative_url validation logged the URL with no redaction at all. Init also read the config flag after the check that leaks. Match on the query alone instead of the whole URL, so redaction survives anything that rewrites the rest of it, and apply it at every site that handles a URL or an error derived from one. Returned errors are rewrapped only when redaction is enabled, so the default configuration keeps propagating the original typed error.
Matching the literal query we built the request with leaves three ways to leak it, all of them reachable through an ordinary redirect: - A redirect to a *different* query. net/http builds its *url.Error from the last request it made, so the URL in the error is the redirect target's, and "?code=..." on a callback is logged in full. - A probe whose own URL has no query. With nothing to match on, redaction was off entirely even when the redirect target carried a query. This is the worst shape, because it is silent. - A redirect that appends to our query, which replaced only the matched prefix and yielded "?<redacted>&token=secret". Redact the URL rather than searching for a string inside a message. A *url.Error carries the URL as a field, so rebuild it with that field cut at the first '?': exact whatever the query holds, including a space, which is legal in a query and survives url.URL.String() verbatim. Rebuilding rather than flattening also preserves the error's type and Unwrap chain, so errors.Is/As don't quietly change behavior when a logging option is set. Init redacts the relative URL the same way. Errors that don't carry a URL field fall back to rewriting the message, but only inside %q-quoted tokens, which is where an error puts a URL, so a '?' in the surrounding prose survives and the message stays readable. Not needing the query up front also collapses the helpers: redactedErr and redactErr differed only in return type, and their names said nothing about that. There is now one redactedErr returning an error, with log sites calling Error() on it, so each site redacts once instead of twice, and runProbe no longer recomputes the target's path to name the query. Also rename a local 'url' that shadowed the newly imported net/url.
|
@markoposavec I took the liberty to follow up with the review fixes. Hope that's okay with you. Please let me know if it's not, I'll avoid it next time. |
Hello,
I've added an opt-in redact_url_query_in_logs field to the HTTP probe config (default false, so existing behavior is unchanged); when enabled, URL query parameters are replaced with "<redacted>" in probe logs.
Some of our legacy endpoints carry sensitive data in query parameters, and when a probe request fails cloudprober logs the full request URL including the query string, so those secrets end up in the logs with no way to opt out short of disabling logging entirely.
Also, in my opinion, probe validation failures shouldn't produce error logs: the system (cloudprober) is working properly - the probe is failing, which isn't a fault of the system itself, so surfacing it at Error feels misleading. But that's really a separate discussion. :)