The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(rust): redact proxy credentials in Debug and build the proxy matcher once
Yujong Leeb341d21a7657
diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lockindex 0cbca96ad57..726d2f484da 100644--- a/litellm-rust/Cargo.lock+++ b/litellm-rust/Cargo.lock@@ -2145,6 +2145,7 @@ dependencies = ["serde_json","thiserror 2.0.19","tokio",+ "veil","webpki-roots",]diff --git a/litellm-rust/crates/http/Cargo.toml b/litellm-rust/crates/http/Cargo.tomlindex 4f94f37a8d5..d4457f5685c 100644--- a/litellm-rust/crates/http/Cargo.toml+++ b/litellm-rust/crates/http/Cargo.toml@@ -17,6 +17,7 @@ rustls.workspace = trueserde_json.workspace = truethiserror.workspace = truetokio.workspace = true+veil.workspace = truewebpki-roots.workspace = true[dev-dependencies]diff --git a/litellm-rust/crates/http/src/media.rs b/litellm-rust/crates/http/src/media.rsindex ae3f55b476a..3b29c9e28a7 100644--- a/litellm-rust/crates/http/src/media.rs+++ b/litellm-rust/crates/http/src/media.rs@@ -103,8 +103,7 @@ impl MediaFetcher {config: &HttpClientConfig,url_policy: UrlPolicy,) -> Result<Self, crate::Error> {- let proxies = config.proxies.clone();- let uses_proxy: ProxyMatch = Arc::new(move |url| proxies.apply_to(url));+ let uses_proxy: ProxyMatch = Arc::new(config.proxies.matcher());Self::with_resolution(pool,config,diff --git a/litellm-rust/crates/http/src/proxy.rs b/litellm-rust/crates/http/src/proxy.rsindex e771631435d..7fedaff4418 100644--- a/litellm-rust/crates/http/src/proxy.rs+++ b/litellm-rust/crates/http/src/proxy.rs@@ -1,10 +1,14 @@use hyper_util::client::proxy::matcher::Matcher;use litellm_core_utils::settings::Lookup;+use veil::Redact;-#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]+#[derive(Clone, Redact, Default, PartialEq, Eq, Hash)]pub struct EnvironmentProxies {+ #[redact]all: String,+ #[redact]http: String,+ #[redact]https: String,no: String,}@@ -25,16 +29,18 @@ impl EnvironmentProxies {}}- pub fn apply_to(&self, url: &reqwest::Url) -> bool {+ pub(crate) fn matcher(&self) -> impl Fn(&reqwest::Url) -> bool + Send + Sync + use<> {let matcher = Matcher::builder().all(self.all.clone()).http(self.http.clone()).https(self.https.clone()).no(self.no.clone()).build();- url.as_str()- .parse::<http::Uri>()- .is_ok_and(|uri| matcher.intercept(&uri).is_some())+ move |url| {+ url.as_str()+ .parse::<http::Uri>()+ .is_ok_and(|uri| matcher.intercept(&uri).is_some())+ }}pub(crate) fn reqwest_proxies(&self) -> Vec<reqwest::Proxy> {@@ -82,7 +88,7 @@ mod tests {#[case] expected: bool,) {let proxies = EnvironmentProxies::from_environment(&env_of(env));- assert_eq!(proxies.apply_to(&url(target)), expected);+ assert_eq!(proxies.matcher()(&url(target)), expected);}#[rstest]@@ -110,7 +116,19 @@ mod tests {("REQUEST_METHOD", "GET"),("HTTPS_PROXY", "http://proxy:3128"),]));- assert!(proxies.apply_to(&url("https://api.test/")));+ assert!(proxies.matcher()(&url("https://api.test/")));+ }++ #[test]+ fn debug_output_hides_proxy_credentials_but_shows_which_variables_are_set() {+ let proxies = EnvironmentProxies::from_environment(&env_of(&[+ ("HTTPS_PROXY", "http://operator:[email protected]:3128"),+ ("NO_PROXY", "internal.test"),+ ]));+ let debug = format!("{proxies:?}");+ assert!(!debug.contains("hunter2") && !debug.contains("operator"));+ assert!(debug.contains("internal.test"));+ assert_ne!(debug, format!("{:?}", EnvironmentProxies::default()));}#[test]