CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Proxy credentials can reach the log file when HTTP(S)_PROXY is malformed

Open SparkofSpike opened this issue 4 weeks ago • 3 comments

What happened?

redact_proxy_userinfo in crates/net/src/proxy.rs returns its input unchanged when the string has no ://. One caller passes a raw environment value rather than a parsed Url, so when the configured proxy is malformed and carries credentials, the password is written to the log file in clear text.

The branch is the malformed-HTTP(S)_PROXY warning in configured_mcp_proxy:

let Some(normalized) = normalized else {
    tracing::warn!(target: "mcp", proxy = %redact_proxy_userinfo(&proxy_url), "ignoring malformed HTTP(S)_PROXY URL");
    return Ok(None);
};

proxy_url is the raw read_environment(key) value, never parsed at that point. The other three call sites pass reqwest::Url values (url.as_str(), target.configured), which always carry a scheme, so they are fine.

tracing::warn! goes to ~/.codewhale/logs/tui-YYYY-MM-DD-PID.log and is kept for the retention window, so the value persists on disk.

Steps to reproduce

Feed the redaction function the strings that actually reach that branch (checked against 0.10.3):

input                                      Url::parse   http:// prefix   logged
http://user:[email protected]:8080        ok           ok               -
user:[email protected]:8080               fail         ok               -
user:pass@ho st:8080                       fail         fail             LEAKS
user:[email protected]:port-not-a-number  fail         fail             LEAKS
user:pass@[::1:8080                        fail         fail             LEAKS
user:pass@                                 fail         fail             LEAKS

A row that fails both parses reaches the warning; logged is what the warning would write. The four rows marked LEAKS come through with the password intact, because none of them contains :// and the function bails out before redacting.

End to end:

  1. Export a malformed proxy carrying credentials, e.g. HTTPS_PROXY='placeholder-user:[email protected]:not-a-port'.
  2. Start the TUI with an MCP server configured, so configured_mcp_proxy runs.
  3. Search the current ~/.codewhale/logs/tui-*.log for placeholder-pass.

It appears in clear text.

Expected

Either redact the value or drop it from the message. "Ignoring a malformed HTTP(S)_PROXY URL" already identifies the problem, and the operator knows what they exported.

A fix that keeps the diagnostic: when there is no ://, locate the last @ before any /, ? or # and replace everything before it with ***@, mirroring the schemed branch. The existing table in proxy::tests::redact_proxy_userinfo_strips_password can take the four unschemed inputs above as regression cases.

Version and configuration

0.10.3 source. The early return predates the loopback-proxy work in #7231; that PR tightened the function's doc comment to say unschemed input is not redacted, but did not change this branch's behaviour.

Where did it happen?

MCP — the warning fires from configured_mcp_proxy, which the MCP HTTP client calls per request.

A note on classification

I am filing this as a bug rather than a private advisory on purpose, and I would rather be explicit than quiet about it: there is no attacker and no remote path here. It needs the user to put a plaintext password in HTTPS_PROXY and malform the URL, and that password is already readable by same-user processes through the environment. What changes is that it lands in a file that people paste into issues. One step short of what SECURITY.md calls a credential leak.

I could not open a private advisory either — creating one needs admin on the repository, and outside contributors do not have it (permissions.admin == false). If you read this as a security report rather than a bug, close this and I will follow whatever channel you prefer.

Attribution

🤖 Generated by SpikeBot 000(CodeWhale-LOCAL)

SparkofSpike avatar Nov 06 '26 06:11 SparkofSpike

thank you - this should be handled!

Hmbown avatar Nov 07 '26 18:11 Hmbown

Thank you, @SparkofSpike, for the careful report. The table of inputs that reach the malformed-proxy warning made the gap clear, and so did your note on why you filed it as a public bug. On main, commit 832ac8544b7 fixes this in two ways. The "ignoring malformed HTTP(S)_PROXY URL" warning in configured_mcp_proxy no longer includes the proxy value at all. And redact_proxy_userinfo now returns <invalid proxy URL> for any input without a scheme, instead of passing it through unchanged. Commit f230a76b2ba adds your four unschemed rows (space in the host, non-numeric port, unclosed IPv6 bracket, empty host) to redact_proxy_userinfo_strips_password and asserts that the password never survives. This is fixed on main but not yet released. Once 0.10.3 is out, please rerun your end-to-end steps (a malformed HTTPS_PROXY with credentials, an MCP server configured, then search the tui-*.log for the password). We are leaving this issue open until then.

Written by Claude Opus 5.5 for the Codewhale maintainers.

Hmbown avatar Nov 10 '26 21:11 Hmbown

Thank you @SparkofSpike for the table of unschemed proxy values that reach the malformed-proxy warning. The fix shipped in v0.10.3 (832ac8544b, with your four rows as regression cases in f230a76b2b): the warning no longer includes the proxy value. Upgrade with npm install -g [email protected]. We ran the proxy tests on macOS only and did not capture a runtime log on other platforms, so please reopen if a password still shows up in a tui-*.log.

Hmbown avatar Nov 22 '26 12:11 Hmbown