Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cli): warn when a proxy URL's credentials cut its host short
lhzapatac94df6ffd3f0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c6a02aca..2973515e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -34,6 +34,15 @@ version in [`docs/changelog/`](docs/changelog/):rejected as containing no extractable text when that was its only cue.WebVTT allows any number of blank lines between blocks; the reader now skipsthem before reading a block.+- The startup warning about unusable proxy variables now also fires when the+ user name or password in `HTTPS_PROXY`, `HTTP_PROXY` or `ALL_PROXY` (or a+ lower-case spelling) holds an unencoded `#`, `/` or `?`. The URI grammar+ ends the host at that character, so the client sent provider and login+ requests to a host made of the start of the credentials, such as+ `alice:18080` for `http://alice:18080#[email protected]:3128`, and the failure+ looked like a connection error to a host nobody configured. The warning+ names the variable and the character, not the value, and the network+ behaviour is unchanged (#1637).## [3.2.2] - 2026-10-22diff --git a/crates/ai-memory-cli/src/proxy_env.rs b/crates/ai-memory-cli/src/proxy_env.rsindex 8f80462e..233ae724 100644--- a/crates/ai-memory-cli/src/proxy_env.rs+++ b/crates/ai-memory-cli/src/proxy_env.rs@@ -4,10 +4,13 @@//! skips a value that is not UTF-8 or does not parse as a URI and carries on//! without a proxy. Provider, OIDC and upgrade requests then go out directly://! a timeout on a network that blocks direct egress, or traffic that bypasses-//! a required proxy on one that does not. The checks below mirror-//! hyper-util 0.1's acceptance rules (`parse_env_uri`) so the operator hears-//! about it; the value itself is never logged, since it often carries a-//! password.+//! a required proxy on one that does not. A value that does parse can still+//! name the wrong proxy: the URI grammar ends the authority at the first `#`,+//! `/` or `?`, so one of them left unencoded in a password cuts the host short+//! and the client tries whatever the user name and password prefix spell. The+//! checks below mirror hyper-util 0.1's acceptance rules (`parse_env_uri`) so+//! the operator hears about it; the value itself is never logged, since it+//! often carries a password.use std::ffi::OsStr;@@ -23,19 +26,19 @@ const PROXY_VARS: [&str; 6] = ["https_proxy",];+const IGNORED: &str = "so the HTTP client ignores it and connects without that proxy";+const MISROUTED: &str = "so the HTTP client connects to a proxy host that was never configured";+/// Log one warning per proxy variable that is set but unusable.pub(crate) fn warn_unusable(env: &RuntimeEnv) {- for (name, reason) in unusable(|name| env.var_os(name)) {- tracing::warn!(- variable = name,- "{name} {reason}, so the HTTP client ignores it and connects without that proxy"- );+ for (name, (reason, effect)) in unusable(|name| env.var_os(name)) {+ tracing::warn!(variable = name, "{name} {reason}, {effect}");}}-fn unusable(- lookup: impl Fn(&str) -> Option<std::ffi::OsString>,-) -> Vec<(&'static str, &'static str)> {+type Problem = (&'static str, &'static str);++fn unusable(lookup: impl Fn(&str) -> Option<std::ffi::OsString>) -> Vec<(&'static str, Problem)> {PROXY_VARS.iter()// Windows matches variable names case-insensitively, so the lower-case@@ -45,28 +48,51 @@ fn unusable(.collect()}-fn problem(value: &OsStr) -> Option<&'static str> {+fn problem(value: &OsStr) -> Option<Problem> {+ let ignored = |reason| Some((reason, IGNORED));let Some(text) = value.to_str() else {- return Some("is not valid UTF-8");+ return ignored("is not valid UTF-8");};// hyper-util treats an empty value as unset, and so does every shell user.if text.is_empty() {return None;}let Ok(uri) = text.parse::<http::Uri>() else {- return Some(+ return ignored("is not a valid URI (percent-encode spaces and non-ASCII characters in \the user name and password)",);};match uri.scheme_str() {None | Some("http" | "https" | "socks4" | "socks4a" | "socks5" | "socks5h") => {}- Some(_) => return Some("uses an unsupported proxy scheme"),+ Some(_) => return ignored("uses an unsupported proxy scheme"),}if uri.authority().is_none() {- return Some("names no proxy host");+ return ignored("names no proxy host");}- None+ cut_userinfo(text).map(|reason| (reason, MISROUTED))+}++/// An `@` after the delimiter that ended the authority means the delimiter sat+/// in the user name or password, and the host the client parsed is a prefix of+/// the credentials.+fn cut_userinfo(text: &str) -> Option<&'static str> {+ let rest = text.split_once("://").map_or(text, |(_, rest)| rest);+ let cut = rest.find(['#', '/', '?'])?;+ if !rest[cut..].contains('@') {+ return None;+ }+ Some(match rest.as_bytes()[cut] {+ b'#' => {+ "has an unencoded `#` before the `@`, which cuts the proxy host short (percent-encode it as %23)"+ }+ b'/' => {+ "has an unencoded `/` before the `@`, which cuts the proxy host short (percent-encode it as %2F)"+ }+ _ => {+ "has an unencoded `?` before the `@`, which cuts the proxy host short (percent-encode it as %3F)"+ }+ })}#[cfg(test)]@@ -84,6 +110,8 @@ mod tests {for value in ["http://proxy.example:3128","http://user:p%C3%[email protected]:3128",+ "http://user:18080%[email protected]:3128",+ "http://proxy.example:3128/","https://proxy.example","proxy.example:3128","socks5h://127.0.0.1:1080",@@ -107,6 +135,28 @@ mod tests {let found = unusable(only("HTTPS_PROXY", value.into()));assert_eq!(found.len(), 1, "{value:?} was not reported");assert_eq!(found[0].0, "HTTPS_PROXY");+ assert_eq!(found[0].1.1, IGNORED);+ }+ }++ /// `alice:18080#[email protected]:3128` parses as host `alice`, port 18080:+ /// the client tunnels there, without credentials, instead of to the proxy.+ #[test]+ fn a_delimiter_in_the_credentials_is_reported_as_misrouting() {+ for (value, delimiter) in [+ ("http://alice:18080#[email protected]:3128", "`#`"),+ ("http://alice:pa#[email protected]:3128", "`#`"),+ ("socks5h://alice#x:[email protected]:1080", "`#`"),+ ("http://alice:a/[email protected]:3128", "`/`"),+ ("http://alice:[email protected]:3128", "`?`"),+ ] {+ let found = unusable(only("HTTPS_PROXY", value.into()));+ assert_eq!(found.len(), 1, "{value:?} was not reported");+ let (name, (reason, effect)) = found[0];+ assert_eq!(name, "HTTPS_PROXY");+ assert_eq!(effect, MISROUTED);+ assert!(reason.contains(delimiter), "{value:?}: {reason}");+ assert!(!reason.contains("alice") && !reason.contains("proxy.example"));}}@@ -117,8 +167,8 @@ mod tests {use std::os::unix::ffi::OsStringExt as _;let value = OsString::from_vec(b"http://user:a\xe7\[email protected]:3128".to_vec());let found = unusable(only("http_proxy", value));- assert_eq!(found, vec![("http_proxy", "is not valid UTF-8")]);- assert!(!found[0].1.contains("proxy.example"));+ assert_eq!(found, vec![("http_proxy", ("is not valid UTF-8", IGNORED))]);+ assert!(!found[0].1.0.contains("proxy.example"));}#[test]