You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several log statements write MongoDB connection URIs verbatim. Because the exporter injects the monitoring user's credentials into the URI before these statements run, the emitted log line contains user:password in cleartext.
This came up while reviewing #1336, which redacts one of these call sites as a side effect of its feature work. The remaining sites are unrelated to that PR and should be fixed separately — hence this issue.
and the fallback path buildURIManually (main.go:291) does the same by string concatenation. A URI supplied directly via --mongodb.uri / MONGODB_URI may of course already embed credentials, which covers the seedlist and buildServerMap cases where buildURI isn't involved.
Severity notes
Site 1 only fires with debug logging enabled. That is not the default, but debug logs are exactly what users attach to support tickets and GitHub issues, so credentials leak into third-party hands routinely.
Sites 2–6 fire at the default log level, on error paths that are easy to hit in practice: a malformed URI, an unresolvable SRV record, or a DNS hiccup. Sites 3 and 4 in particular are plain operational failures, not misconfiguration — an SRV lookup failure on a mongodb+srv:// URI will print the credentials on every affected startup.
Sites 2, 5, and 6 log because parsing failed, so Redacted() is not available on the parsed value — those need string-level scrubbing (or should log only the host portion / omit the URI entirely and rely on the error).
A shared helper is preferable to per-site fixes so new logging doesn't reintroduce the leak. feat: add dynamic target support #1336 adds an unexported redactMongoURI in package main; exporter/seedlist.go and exporter/server.go live in package exporter and cannot reuse it as written. Placing it somewhere both packages can import (e.g. internal/) would be worthwhile.
Describe the bug
Several log statements write MongoDB connection URIs verbatim. Because the exporter injects the monitoring user's credentials into the URI before these statements run, the emitted log line contains
user:passwordin cleartext.This came up while reviewing #1336, which redacts one of these call sites as a side effect of its feature work. The remaining sites are unrelated to that PR and should be fixed separately — hence this issue.
Affected call sites (all on
main@ 9585218)main.go:143—log.Debug("Connection URI", "uri", uri)--log.level=debug)exporter/seedlist.go:31—log.Fatalf("Failed to parse URI %s: %v", uri, err)exporter/seedlist.go:36—logger.Error("Failed to lookup SRV records", "uri", uri, ...)exporter/seedlist.go:41—logger.Error("No SRV records found", "uri", uri)main.go:259—log.Fatalf("Failed to parse URI %s: %v", hosturl, err)(the--split-clusterpath)exporter/server.go:181—log.Error("Unable to parse provided address as url", "address", e.opts.URI, ...)Why the URI carries credentials
buildURI(main.go:300) injects them explicitly:and the fallback path
buildURIManually(main.go:291) does the same by string concatenation. A URI supplied directly via--mongodb.uri/MONGODB_URImay of course already embed credentials, which covers the seedlist andbuildServerMapcases wherebuildURIisn't involved.Severity notes
mongodb+srv://URI will print the credentials on every affected startup.Expected behavior
No log statement should emit a MongoDB URI with a readable password, at any level.
Suggested fix
(*url.URL).Redacted()handles the cases where the URI parses:Two things to watch when applying it:
Redacted()is not available on the parsed value — those need string-level scrubbing (or should log only the host portion / omit the URI entirely and rely on the error).redactMongoURIinpackage main;exporter/seedlist.goandexporter/server.golive inpackage exporterand cannot reuse it as written. Placing it somewhere both packages can import (e.g.internal/) would be worthwhile.Related
Environment
Not environment-specific; applies to all builds from
main.