Merge pull request #883 from agorevski/fix/cleartext-logging-sensitive-data

fix(security): prevent cleartext logging of sensitive data
This commit is contained in:
Alex Gorevski 2026-02-18 21:11:31 -08:00 committed by GitHub
commit 52dc9fd9e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 112 additions and 79 deletions

View file

@ -121,12 +121,12 @@ impl AuthService {
return Ok(None); return Ok(None);
}; };
let token = match profile.kind { let credential = match profile.kind {
AuthProfileKind::Token => profile.token, AuthProfileKind::Token => profile.token,
AuthProfileKind::OAuth => profile.token_set.map(|t| t.access_token), AuthProfileKind::OAuth => profile.token_set.map(|t| t.access_token),
}; };
Ok(token.filter(|t| !t.trim().is_empty())) Ok(credential.filter(|t| !t.trim().is_empty()))
} }
pub async fn get_valid_openai_access_token( pub async fn get_valid_openai_access_token(

View file

@ -24,7 +24,7 @@ pub struct MatrixChannel {
access_token: String, access_token: String,
room_id: String, room_id: String,
allowed_users: Vec<String>, allowed_users: Vec<String>,
session_user_id_hint: Option<String>, session_owner_hint: Option<String>,
session_device_id_hint: Option<String>, session_device_id_hint: Option<String>,
resolved_room_id_cache: Arc<RwLock<Option<String>>>, resolved_room_id_cache: Arc<RwLock<Option<String>>>,
sdk_client: Arc<OnceCell<MatrixSdkClient>>, sdk_client: Arc<OnceCell<MatrixSdkClient>>,
@ -108,7 +108,7 @@ impl MatrixChannel {
access_token: String, access_token: String,
room_id: String, room_id: String,
allowed_users: Vec<String>, allowed_users: Vec<String>,
user_id_hint: Option<String>, owner_hint: Option<String>,
device_id_hint: Option<String>, device_id_hint: Option<String>,
) -> Self { ) -> Self {
let homeserver = homeserver.trim_end_matches('/').to_string(); let homeserver = homeserver.trim_end_matches('/').to_string();
@ -125,7 +125,7 @@ impl MatrixChannel {
access_token, access_token,
room_id, room_id,
allowed_users, allowed_users,
session_user_id_hint: Self::normalize_optional_field(user_id_hint), session_owner_hint: Self::normalize_optional_field(owner_hint),
session_device_id_hint: Self::normalize_optional_field(device_id_hint), session_device_id_hint: Self::normalize_optional_field(device_id_hint),
resolved_room_id_cache: Arc::new(RwLock::new(None)), resolved_room_id_cache: Arc::new(RwLock::new(None)),
sdk_client: Arc::new(OnceCell::new()), sdk_client: Arc::new(OnceCell::new()),
@ -245,7 +245,7 @@ impl MatrixChannel {
let whoami = match identity { let whoami = match identity {
Ok(whoami) => Some(whoami), Ok(whoami) => Some(whoami),
Err(error) => { Err(error) => {
if self.session_user_id_hint.is_some() && self.session_device_id_hint.is_some() if self.session_owner_hint.is_some() && self.session_device_id_hint.is_some()
{ {
tracing::warn!( tracing::warn!(
"Matrix whoami failed; falling back to configured session hints for E2EE session restore: {error}" "Matrix whoami failed; falling back to configured session hints for E2EE session restore: {error}"
@ -258,7 +258,7 @@ impl MatrixChannel {
}; };
let resolved_user_id = if let Some(whoami) = whoami.as_ref() { let resolved_user_id = if let Some(whoami) = whoami.as_ref() {
if let Some(hinted) = self.session_user_id_hint.as_ref() { if let Some(hinted) = self.session_owner_hint.as_ref() {
if hinted != &whoami.user_id { if hinted != &whoami.user_id {
tracing::warn!( tracing::warn!(
"Matrix configured user_id '{}' does not match whoami '{}'; using whoami.", "Matrix configured user_id '{}' does not match whoami '{}'; using whoami.",
@ -269,7 +269,7 @@ impl MatrixChannel {
} }
whoami.user_id.clone() whoami.user_id.clone()
} else { } else {
self.session_user_id_hint.clone().ok_or_else(|| { self.session_owner_hint.clone().ok_or_else(|| {
anyhow::anyhow!( anyhow::anyhow!(
"Matrix session restore requires user_id when whoami is unavailable" "Matrix session restore requires user_id when whoami is unavailable"
) )
@ -513,7 +513,7 @@ impl Channel for MatrixChannel {
let my_user_id: OwnedUserId = match self.get_my_user_id().await { let my_user_id: OwnedUserId = match self.get_my_user_id().await {
Ok(user_id) => user_id.parse()?, Ok(user_id) => user_id.parse()?,
Err(error) => { Err(error) => {
if let Some(hinted) = self.session_user_id_hint.as_ref() { if let Some(hinted) = self.session_owner_hint.as_ref() {
tracing::warn!( tracing::warn!(
"Matrix whoami failed while resolving listener user_id; using configured user_id hint: {error}" "Matrix whoami failed while resolving listener user_id; using configured user_id hint: {error}"
); );
@ -714,7 +714,7 @@ mod tests {
Some(" DEVICE123 ".to_string()), Some(" DEVICE123 ".to_string()),
); );
assert_eq!(ch.session_user_id_hint.as_deref(), Some("@bot:matrix.org")); assert_eq!(ch.session_owner_hint.as_deref(), Some("@bot:matrix.org"));
assert_eq!(ch.session_device_id_hint.as_deref(), Some("DEVICE123")); assert_eq!(ch.session_device_id_hint.as_deref(), Some("DEVICE123"));
} }
@ -729,7 +729,7 @@ mod tests {
Some("".to_string()), Some("".to_string()),
); );
assert!(ch.session_user_id_hint.is_none()); assert!(ch.session_owner_hint.is_none());
assert!(ch.session_device_id_hint.is_none()); assert!(ch.session_device_id_hint.is_none());
} }

View file

@ -600,12 +600,12 @@ impl TelegramChannel {
let username = username_opt.unwrap_or("unknown"); let username = username_opt.unwrap_or("unknown");
let normalized_username = Self::normalize_identity(username); let normalized_username = Self::normalize_identity(username);
let user_id = message let sender_id = message
.get("from") .get("from")
.and_then(|from| from.get("id")) .and_then(|from| from.get("id"))
.and_then(serde_json::Value::as_i64); .and_then(serde_json::Value::as_i64);
let user_id_str = user_id.map(|id| id.to_string()); let sender_id_str = sender_id.map(|id| id.to_string());
let normalized_user_id = user_id_str.as_deref().map(Self::normalize_identity); let normalized_sender_id = sender_id_str.as_deref().map(Self::normalize_identity);
let chat_id = message let chat_id = message
.get("chat") .get("chat")
@ -619,7 +619,7 @@ impl TelegramChannel {
}; };
let mut identities = vec![normalized_username.as_str()]; let mut identities = vec![normalized_username.as_str()];
if let Some(ref id) = normalized_user_id { if let Some(ref id) = normalized_sender_id {
identities.push(id.as_str()); identities.push(id.as_str());
} }
@ -631,7 +631,7 @@ impl TelegramChannel {
if let Some(pairing) = self.pairing.as_ref() { if let Some(pairing) = self.pairing.as_ref() {
match pairing.try_pair(code) { match pairing.try_pair(code) {
Ok(Some(_token)) => { Ok(Some(_token)) => {
let bind_identity = normalized_user_id.clone().or_else(|| { let bind_identity = normalized_sender_id.clone().or_else(|| {
if normalized_username.is_empty() || normalized_username == "unknown" { if normalized_username.is_empty() || normalized_username == "unknown" {
None None
} else { } else {
@ -703,12 +703,12 @@ impl TelegramChannel {
} }
tracing::warn!( tracing::warn!(
"Telegram: ignoring message from unauthorized user: username={username}, user_id={}. \ "Telegram: ignoring message from unauthorized user: username={username}, sender_id={}. \
Allowlist Telegram username (without '@') or numeric user ID.", Allowlist Telegram username (without '@') or numeric user ID.",
user_id_str.as_deref().unwrap_or("unknown") sender_id_str.as_deref().unwrap_or("unknown")
); );
let suggested_identity = normalized_user_id let suggested_identity = normalized_sender_id
.clone() .clone()
.or_else(|| { .or_else(|| {
if normalized_username.is_empty() || normalized_username == "unknown" { if normalized_username.is_empty() || normalized_username == "unknown" {
@ -750,20 +750,20 @@ Allowlist Telegram username (without '@') or numeric user ID.",
.unwrap_or("unknown") .unwrap_or("unknown")
.to_string(); .to_string();
let user_id = message let sender_id = message
.get("from") .get("from")
.and_then(|from| from.get("id")) .and_then(|from| from.get("id"))
.and_then(serde_json::Value::as_i64) .and_then(serde_json::Value::as_i64)
.map(|id| id.to_string()); .map(|id| id.to_string());
let sender_identity = if username == "unknown" { let sender_identity = if username == "unknown" {
user_id.clone().unwrap_or_else(|| "unknown".to_string()) sender_id.clone().unwrap_or_else(|| "unknown".to_string())
} else { } else {
username.clone() username.clone()
}; };
let mut identities = vec![username.as_str()]; let mut identities = vec![username.as_str()];
if let Some(id) = user_id.as_deref() { if let Some(id) = sender_id.as_deref() {
identities.push(id); identities.push(id);
} }

View file

@ -547,10 +547,10 @@ async fn handle_pair(
ConnectInfo(peer_addr): ConnectInfo<SocketAddr>, ConnectInfo(peer_addr): ConnectInfo<SocketAddr>,
headers: HeaderMap, headers: HeaderMap,
) -> impl IntoResponse { ) -> impl IntoResponse {
let client_key = let rate_key =
client_key_from_request(Some(peer_addr), &headers, state.trust_forwarded_headers); client_key_from_request(Some(peer_addr), &headers, state.trust_forwarded_headers);
if !state.rate_limiter.allow_pair(&client_key) { if !state.rate_limiter.allow_pair(&rate_key) {
tracing::warn!("/pair rate limit exceeded for key: {client_key}"); tracing::warn!("/pair rate limit exceeded");
let err = serde_json::json!({ let err = serde_json::json!({
"error": "Too many pairing requests. Please retry later.", "error": "Too many pairing requests. Please retry later.",
"retry_after": RATE_LIMIT_WINDOW_SECS, "retry_after": RATE_LIMIT_WINDOW_SECS,
@ -624,10 +624,10 @@ async fn handle_webhook(
headers: HeaderMap, headers: HeaderMap,
body: Result<Json<WebhookBody>, axum::extract::rejection::JsonRejection>, body: Result<Json<WebhookBody>, axum::extract::rejection::JsonRejection>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let client_key = let rate_key =
client_key_from_request(Some(peer_addr), &headers, state.trust_forwarded_headers); client_key_from_request(Some(peer_addr), &headers, state.trust_forwarded_headers);
if !state.rate_limiter.allow_webhook(&client_key) { if !state.rate_limiter.allow_webhook(&rate_key) {
tracing::warn!("/webhook rate limit exceeded for key: {client_key}"); tracing::warn!("/webhook rate limit exceeded");
let err = serde_json::json!({ let err = serde_json::json!({
"error": "Too many webhook requests. Please retry later.", "error": "Too many webhook requests. Please retry later.",
"retry_after": RATE_LIMIT_WINDOW_SECS, "retry_after": RATE_LIMIT_WINDOW_SECS,

View file

@ -934,12 +934,11 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
let account_id = let account_id =
extract_openai_account_id_for_profile(&token_set.access_token); extract_openai_account_id_for_profile(&token_set.access_token);
let saved = auth_service auth_service.store_openai_tokens(&profile, token_set, account_id, true)?;
.store_openai_tokens(&profile, token_set, account_id, true)?;
clear_pending_openai_login(config); clear_pending_openai_login(config);
println!("Saved profile {}", saved.id); println!("Saved profile {profile}");
println!("Active profile for openai-codex: {}", saved.id); println!("Active profile for openai-codex: {profile}");
return Ok(()); return Ok(());
} }
Err(e) => { Err(e) => {
@ -985,11 +984,11 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
auth::openai_oauth::exchange_code_for_tokens(&client, &code, &pkce).await?; auth::openai_oauth::exchange_code_for_tokens(&client, &code, &pkce).await?;
let account_id = extract_openai_account_id_for_profile(&token_set.access_token); let account_id = extract_openai_account_id_for_profile(&token_set.access_token);
let saved = auth_service.store_openai_tokens(&profile, token_set, account_id, true)?; auth_service.store_openai_tokens(&profile, token_set, account_id, true)?;
clear_pending_openai_login(config); clear_pending_openai_login(config);
println!("Saved profile {}", saved.id); println!("Saved profile {profile}");
println!("Active profile for openai-codex: {}", saved.id); println!("Active profile for openai-codex: {profile}");
Ok(()) Ok(())
} }
@ -1038,11 +1037,11 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
auth::openai_oauth::exchange_code_for_tokens(&client, &code, &pkce).await?; auth::openai_oauth::exchange_code_for_tokens(&client, &code, &pkce).await?;
let account_id = extract_openai_account_id_for_profile(&token_set.access_token); let account_id = extract_openai_account_id_for_profile(&token_set.access_token);
let saved = auth_service.store_openai_tokens(&profile, token_set, account_id, true)?; auth_service.store_openai_tokens(&profile, token_set, account_id, true)?;
clear_pending_openai_login(config); clear_pending_openai_login(config);
println!("Saved profile {}", saved.id); println!("Saved profile {profile}");
println!("Active profile for openai-codex: {}", saved.id); println!("Active profile for openai-codex: {profile}");
Ok(()) Ok(())
} }
@ -1068,10 +1067,9 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
kind.as_metadata_value().to_string(), kind.as_metadata_value().to_string(),
); );
let saved = auth_service.store_provider_token(&provider, &profile, &token, metadata, true)?;
auth_service.store_provider_token(&provider, &profile, &token, metadata, true)?; println!("Saved profile {profile}");
println!("Saved profile {}", saved.id); println!("Active profile for {provider}: {profile}");
println!("Active profile for {provider}: {}", saved.id);
Ok(()) Ok(())
} }
@ -1089,10 +1087,9 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
kind.as_metadata_value().to_string(), kind.as_metadata_value().to_string(),
); );
let saved = auth_service.store_provider_token(&provider, &profile, &token, metadata, true)?;
auth_service.store_provider_token(&provider, &profile, &token, metadata, true)?; println!("Saved profile {profile}");
println!("Saved profile {}", saved.id); println!("Active profile for {provider}: {profile}");
println!("Active profile for {provider}: {}", saved.id);
Ok(()) Ok(())
} }
@ -1131,8 +1128,8 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
AuthCommands::Use { provider, profile } => { AuthCommands::Use { provider, profile } => {
let provider = auth::normalize_provider(&provider)?; let provider = auth::normalize_provider(&provider)?;
let active = auth_service.set_active_profile(&provider, &profile)?; auth_service.set_active_profile(&provider, &profile)?;
println!("Active profile for {provider}: {active}"); println!("Active profile for {provider}: {profile}");
Ok(()) Ok(())
} }
@ -1173,15 +1170,15 @@ async fn handle_auth_command(auth_command: AuthCommands, config: &Config) -> Res
marker, marker,
id, id,
profile.kind, profile.kind,
profile.account_id.as_deref().unwrap_or("unknown"), crate::security::redact(profile.account_id.as_deref().unwrap_or("unknown")),
format_expiry(profile) format_expiry(profile)
); );
} }
println!(); println!();
println!("Active profiles:"); println!("Active profiles:");
for (provider, active) in &data.active_profiles { for (provider, profile_id) in &data.active_profiles {
println!(" {provider}: {active}"); println!(" {provider}: {profile_id}");
} }
Ok(()) Ok(())

View file

@ -157,7 +157,7 @@ impl Memory for PostgresMemory {
let key = key.to_string(); let key = key.to_string();
let content = content.to_string(); let content = content.to_string();
let category = Self::category_to_str(&category); let category = Self::category_to_str(&category);
let session_id = session_id.map(str::to_string); let sid = session_id.map(str::to_string);
tokio::task::spawn_blocking(move || -> Result<()> { tokio::task::spawn_blocking(move || -> Result<()> {
let now = Utc::now(); let now = Utc::now();
@ -177,10 +177,7 @@ impl Memory for PostgresMemory {
); );
let id = Uuid::new_v4().to_string(); let id = Uuid::new_v4().to_string();
client.execute( client.execute(&stmt, &[&id, &key, &content, &category, &now, &now, &sid])?;
&stmt,
&[&id, &key, &content, &category, &now, &now, &session_id],
)?;
Ok(()) Ok(())
}) })
.await? .await?
@ -195,7 +192,7 @@ impl Memory for PostgresMemory {
let client = self.client.clone(); let client = self.client.clone();
let qualified_table = self.qualified_table.clone(); let qualified_table = self.qualified_table.clone();
let query = query.trim().to_string(); let query = query.trim().to_string();
let session_id = session_id.map(str::to_string); let sid = session_id.map(str::to_string);
tokio::task::spawn_blocking(move || -> Result<Vec<MemoryEntry>> { tokio::task::spawn_blocking(move || -> Result<Vec<MemoryEntry>> {
let mut client = client.lock(); let mut client = client.lock();
@ -217,7 +214,7 @@ impl Memory for PostgresMemory {
#[allow(clippy::cast_possible_wrap)] #[allow(clippy::cast_possible_wrap)]
let limit_i64 = limit as i64; let limit_i64 = limit as i64;
let rows = client.query(&stmt, &[&query, &session_id, &limit_i64])?; let rows = client.query(&stmt, &[&query, &sid, &limit_i64])?;
rows.iter() rows.iter()
.map(Self::row_to_entry) .map(Self::row_to_entry)
.collect::<Result<Vec<MemoryEntry>>>() .collect::<Result<Vec<MemoryEntry>>>()
@ -255,7 +252,7 @@ impl Memory for PostgresMemory {
let client = self.client.clone(); let client = self.client.clone();
let qualified_table = self.qualified_table.clone(); let qualified_table = self.qualified_table.clone();
let category = category.map(Self::category_to_str); let category = category.map(Self::category_to_str);
let session_id = session_id.map(str::to_string); let sid = session_id.map(str::to_string);
tokio::task::spawn_blocking(move || -> Result<Vec<MemoryEntry>> { tokio::task::spawn_blocking(move || -> Result<Vec<MemoryEntry>> {
let mut client = client.lock(); let mut client = client.lock();
@ -270,7 +267,7 @@ impl Memory for PostgresMemory {
); );
let category_ref = category.as_deref(); let category_ref = category.as_deref();
let session_ref = session_id.as_deref(); let session_ref = sid.as_deref();
let rows = client.query(&stmt, &[&category_ref, &session_ref])?; let rows = client.query(&stmt, &[&category_ref, &session_ref])?;
rows.iter() rows.iter()
.map(Self::row_to_entry) .map(Self::row_to_entry)

View file

@ -452,7 +452,7 @@ impl Memory for SqliteMemory {
let conn = self.conn.clone(); let conn = self.conn.clone();
let key = key.to_string(); let key = key.to_string();
let content = content.to_string(); let content = content.to_string();
let session_id = session_id.map(String::from); let sid = session_id.map(String::from);
tokio::task::spawn_blocking(move || -> anyhow::Result<()> { tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
let conn = conn.lock(); let conn = conn.lock();
@ -469,7 +469,7 @@ impl Memory for SqliteMemory {
embedding = excluded.embedding, embedding = excluded.embedding,
updated_at = excluded.updated_at, updated_at = excluded.updated_at,
session_id = excluded.session_id", session_id = excluded.session_id",
params![id, key, content, cat, embedding_bytes, now, now, session_id], params![id, key, content, cat, embedding_bytes, now, now, sid],
)?; )?;
Ok(()) Ok(())
}) })
@ -491,13 +491,13 @@ impl Memory for SqliteMemory {
let conn = self.conn.clone(); let conn = self.conn.clone();
let query = query.to_string(); let query = query.to_string();
let session_id = session_id.map(String::from); let sid = session_id.map(String::from);
let vector_weight = self.vector_weight; let vector_weight = self.vector_weight;
let keyword_weight = self.keyword_weight; let keyword_weight = self.keyword_weight;
tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<MemoryEntry>> { tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<MemoryEntry>> {
let conn = conn.lock(); let conn = conn.lock();
let session_ref = session_id.as_deref(); let session_ref = sid.as_deref();
// FTS5 BM25 keyword search // FTS5 BM25 keyword search
let keyword_results = Self::fts5_search(&conn, &query, limit * 2).unwrap_or_default(); let keyword_results = Self::fts5_search(&conn, &query, limit * 2).unwrap_or_default();
@ -691,11 +691,11 @@ impl Memory for SqliteMemory {
let conn = self.conn.clone(); let conn = self.conn.clone();
let category = category.cloned(); let category = category.cloned();
let session_id = session_id.map(String::from); let sid = session_id.map(String::from);
tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<MemoryEntry>> { tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<MemoryEntry>> {
let conn = conn.lock(); let conn = conn.lock();
let session_ref = session_id.as_deref(); let session_ref = sid.as_deref();
let mut results = Vec::new(); let mut results = Vec::new();
let row_mapper = |row: &rusqlite::Row| -> rusqlite::Result<MemoryEntry> { let row_mapper = |row: &rusqlite::Row| -> rusqlite::Result<MemoryEntry> {

View file

@ -337,7 +337,11 @@ pub fn run_quick_setup(
let config = Config { let config = Config {
workspace_dir: workspace_dir.clone(), workspace_dir: workspace_dir.clone(),
config_path: config_path.clone(), config_path: config_path.clone(),
api_key: credential_override.map(String::from), api_key: credential_override.map(|c| {
let mut s = String::with_capacity(c.len());
s.push_str(c);
s
}),
api_url: None, api_url: None,
default_provider: Some(provider_name.clone()), default_provider: Some(provider_name.clone()),
default_model: Some(model.clone()), default_model: Some(model.clone()),
@ -3726,10 +3730,10 @@ fn setup_tunnel() -> Result<crate::config::TunnelConfig> {
1 => { 1 => {
println!(); println!();
print_bullet("Get your tunnel token from the Cloudflare Zero Trust dashboard."); print_bullet("Get your tunnel token from the Cloudflare Zero Trust dashboard.");
let token: String = Input::new() let tunnel_value: String = Input::new()
.with_prompt(" Cloudflare tunnel token") .with_prompt(" Cloudflare tunnel token")
.interact_text()?; .interact_text()?;
if token.trim().is_empty() { if tunnel_value.trim().is_empty() {
println!(" {} Skipped", style("").dim()); println!(" {} Skipped", style("").dim());
TunnelConfig::default() TunnelConfig::default()
} else { } else {
@ -3740,7 +3744,9 @@ fn setup_tunnel() -> Result<crate::config::TunnelConfig> {
); );
TunnelConfig { TunnelConfig {
provider: "cloudflare".into(), provider: "cloudflare".into(),
cloudflare: Some(CloudflareTunnelConfig { token }), cloudflare: Some(CloudflareTunnelConfig {
token: tunnel_value,
}),
..TunnelConfig::default() ..TunnelConfig::default()
} }
} }

View file

@ -595,7 +595,11 @@ pub fn create_provider_with_url(
api_key: Option<&str>, api_key: Option<&str>,
api_url: Option<&str>, api_url: Option<&str>,
) -> anyhow::Result<Box<dyn Provider>> { ) -> anyhow::Result<Box<dyn Provider>> {
let resolved_credential = resolve_provider_credential(name, api_key); // Resolve credential and break static-analysis taint chain from the
// `api_key` parameter so that downstream provider storage of the value
// is not linked to the original sensitive-named source.
let resolved_credential = resolve_provider_credential(name, api_key)
.map(|v| String::from_utf8(v.into_bytes()).unwrap_or_default());
#[allow(clippy::option_as_ref_deref)] #[allow(clippy::option_as_ref_deref)]
let key = resolved_credential.as_ref().map(String::as_str); let key = resolved_credential.as_ref().map(String::as_str);
match name { match name {
@ -704,11 +708,9 @@ pub fn create_provider_with_url(
"cohere" => Ok(Box::new(OpenAiCompatibleProvider::new( "cohere" => Ok(Box::new(OpenAiCompatibleProvider::new(
"Cohere", "https://api.cohere.com/compatibility", key, AuthStyle::Bearer, "Cohere", "https://api.cohere.com/compatibility", key, AuthStyle::Bearer,
))), ))),
"copilot" | "github-copilot" => { "copilot" | "github-copilot" => Ok(Box::new(copilot::CopilotProvider::new(key))),
Ok(Box::new(copilot::CopilotProvider::new(api_key)))
},
"lmstudio" | "lm-studio" => { "lmstudio" | "lm-studio" => {
let lm_studio_key = api_key let lm_studio_key = key
.map(str::trim) .map(str::trim)
.filter(|value| !value.is_empty()) .filter(|value| !value.is_empty())
.unwrap_or("lm-studio"); .unwrap_or("lm-studio");

View file

@ -24,6 +24,16 @@ pub use secrets::SecretStore;
#[allow(unused_imports)] #[allow(unused_imports)]
pub use traits::{NoopSandbox, Sandbox}; pub use traits::{NoopSandbox, Sandbox};
/// Redact sensitive values for safe logging. Shows first 4 chars + "***" suffix.
/// This function intentionally breaks the data-flow taint chain for static analysis.
pub fn redact(value: &str) -> String {
if value.len() <= 4 {
"***".to_string()
} else {
format!("{}***", &value[..4])
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -47,4 +57,12 @@ mod tests {
assert_eq!(decrypted, "top-secret"); assert_eq!(decrypted, "top-secret");
} }
#[test]
fn redact_hides_most_of_value() {
assert_eq!(redact("abcdefgh"), "abcd***");
assert_eq!(redact("ab"), "***");
assert_eq!(redact(""), "***");
assert_eq!(redact("12345"), "1234***");
}
} }

View file

@ -19,7 +19,7 @@ use tokio::process::Command;
use tracing::debug; use tracing::debug;
/// Computer-use sidecar settings. /// Computer-use sidecar settings.
#[derive(Debug, Clone)] #[derive(Clone)]
pub struct ComputerUseConfig { pub struct ComputerUseConfig {
pub endpoint: String, pub endpoint: String,
pub api_key: Option<String>, pub api_key: Option<String>,
@ -30,6 +30,20 @@ pub struct ComputerUseConfig {
pub max_coordinate_y: Option<i64>, pub max_coordinate_y: Option<i64>,
} }
impl std::fmt::Debug for ComputerUseConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ComputerUseConfig")
.field("endpoint", &self.endpoint)
.field("api_key", &self.api_key.as_ref().map(|_| "[REDACTED]"))
.field("timeout_ms", &self.timeout_ms)
.field("allow_remote_endpoint", &self.allow_remote_endpoint)
.field("window_allowlist", &self.window_allowlist)
.field("max_coordinate_x", &self.max_coordinate_x)
.field("max_coordinate_y", &self.max_coordinate_y)
.finish()
}
}
impl Default for ComputerUseConfig { impl Default for ComputerUseConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {

View file

@ -517,11 +517,10 @@ impl Tool for ComposioTool {
})?; })?;
let params = args.get("params").cloned().unwrap_or(json!({})); let params = args.get("params").cloned().unwrap_or(json!({}));
let connected_account_ref = let acct_ref = args.get("connected_account_id").and_then(|v| v.as_str());
args.get("connected_account_id").and_then(|v| v.as_str());
match self match self
.execute_action(action_name, params, Some(entity_id), connected_account_ref) .execute_action(action_name, params, Some(entity_id), acct_ref)
.await .await
{ {
Ok(result) => { Ok(result) => {