Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(connect): preserve Mochi basic auth (SCR-418)

Ezra Ellette42387cda849b
diff --git a/crates/screenpipe-connect/src/connections/lexi.rs b/crates/screenpipe-connect/src/connections/lexi.rs
index 0cb59df0a..c706bb960 100644
--- a/crates/screenpipe-connect/src/connections/lexi.rs
+++ b/crates/screenpipe-connect/src/connections/lexi.rs
@@ -36,14 +36,22 @@ static DEF: IntegrationDef = IntegrationDef {
pub struct Lexi;
+fn require_non_empty_str<'a>(creds: &'a Map<String, Value>, key: &str) -> Result<&'a str> {
+ let value = require_str(creds, key)?;
+ if value.is_empty() {
+ anyhow::bail!("missing required field: {}", key);
+ }
+ Ok(value)
+}
+
impl Lexi {
async fn test_against_base_url(
client: &reqwest::Client,
creds: &Map<String, Value>,
base_url: &str,
) -> Result<String> {
- let api_key_id = require_str(creds, "api_key_id")?;
- let key_secret = require_str(creds, "key_secret")?;
+ let api_key_id = require_non_empty_str(creds, "api_key_id")?;
+ let key_secret = require_non_empty_str(creds, "key_secret")?;
let endpoint = format!("{}/v1/users", base_url.trim_end_matches('/'));
let resp = client
.get(&endpoint)
@@ -74,9 +82,11 @@ impl Lexi {
if !status.is_success() {
let body = resp.text().await.unwrap_or_default();
- let redacted = body
- .replace(api_key_id, "[redacted]")
- .replace(key_secret, "[redacted]");
+ let mut credentials = [api_key_id, key_secret];
+ credentials.sort_by_key(|value| std::cmp::Reverse(value.len()));
+ let redacted = credentials.into_iter().fold(body, |text, credential| {
+ text.replace(credential, "[redacted]")
+ });
let summary: String = redacted.chars().take(500).collect();
anyhow::bail!("Leexi returned {}: {}", status, summary);
}
@@ -234,6 +244,23 @@ mod tests {
assert!(server.received_requests().await.unwrap().is_empty());
}
+ #[tokio::test]
+ async fn test_rejects_empty_key_id_before_network() {
+ let server = MockServer::start().await;
+ let creds = Map::from_iter([
+ ("api_key_id".into(), Value::String(String::new())),
+ ("key_secret".into(), Value::String("key-secret".into())),
+ ]);
+
+ let error = Lexi::test_against_base_url(&reqwest::Client::new(), &creds, &server.uri())
+ .await
+ .unwrap_err()
+ .to_string();
+
+ assert!(error.contains("missing required field: api_key_id"));
+ assert!(server.received_requests().await.unwrap().is_empty());
+ }
+
#[tokio::test]
async fn test_rejects_missing_key_secret_before_network() {
let server = MockServer::start().await;
@@ -248,6 +275,23 @@ mod tests {
assert!(server.received_requests().await.unwrap().is_empty());
}
+ #[tokio::test]
+ async fn test_rejects_empty_key_secret_before_network() {
+ let server = MockServer::start().await;
+ let creds = Map::from_iter([
+ ("api_key_id".into(), Value::String("key-id".into())),
+ ("key_secret".into(), Value::String(String::new())),
+ ]);
+
+ let error = Lexi::test_against_base_url(&reqwest::Client::new(), &creds, &server.uri())
+ .await
+ .unwrap_err()
+ .to_string();
+
+ assert!(error.contains("missing required field: key_secret"));
+ assert!(server.received_requests().await.unwrap().is_empty());
+ }
+
#[tokio::test]
async fn test_unauthorized_error_tells_user_to_check_both_credentials() {
let server = MockServer::start().await;
@@ -363,4 +407,26 @@ mod tests {
assert!(!error.contains("key-secret"));
assert!(error.len() < 600);
}
+
+ #[tokio::test]
+ async fn test_unexpected_error_redacts_overlapping_credentials() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/v1/users"))
+ .respond_with(ResponseTemplate::new(500).set_body_string("abcdef"))
+ .mount(&server)
+ .await;
+ let creds = Map::from_iter([
+ ("api_key_id".into(), Value::String("abc".into())),
+ ("key_secret".into(), Value::String("abcdef".into())),
+ ]);
+
+ let error = Lexi::test_against_base_url(&reqwest::Client::new(), &creds, &server.uri())
+ .await
+ .unwrap_err()
+ .to_string();
+
+ assert!(!error.contains("def"));
+ assert!(error.contains("[redacted]"));
+ }
}
diff --git a/crates/screenpipe-connect/src/connections/mochi.rs b/crates/screenpipe-connect/src/connections/mochi.rs
index 7f27c5bea..61574d4d7 100644
--- a/crates/screenpipe-connect/src/connections/mochi.rs
+++ b/crates/screenpipe-connect/src/connections/mochi.rs
@@ -40,14 +40,12 @@ impl Integration for Mochi {
fn proxy_config(&self) -> Option<&'static ProxyConfig> {
// Mochi uses HTTP Basic auth with the API key as the *username* and an
- // empty password (curl -u "<api_key>:"). There is no password field, so
- // `password_key` points at a key that is never present in creds — the
- // proxy resolves a missing key to "", yielding Basic(api_key, "").
+ // empty password (curl -u "<api_key>:"). Model that contract explicitly
+ // so two-field Basic integrations can reject incomplete credentials.
static CFG: ProxyConfig = ProxyConfig {
base_url: "https://app.mochi.cards/api",
- auth: ProxyAuth::BasicAuth {
+ auth: ProxyAuth::BasicAuthEmptyPassword {
username_key: "api_key",
- password_key: "_unused",
},
extra_headers: &[],
};
diff --git a/crates/screenpipe-connect/src/connections/mod.rs b/crates/screenpipe-connect/src/connections/mod.rs
index b622eb220..f12f7e858 100644
--- a/crates/screenpipe-connect/src/connections/mod.rs
+++ b/crates/screenpipe-connect/src/connections/mod.rs
@@ -151,6 +151,8 @@ pub enum ProxyAuth {
username_key: &'static str,
password_key: &'static str,
},
+ /// HTTP Basic Auth using one credential field as the username and an empty password.
+ BasicAuthEmptyPassword { username_key: &'static str },
/// No auth needed (e.g. webhook-based integrations where the URL is the secret).
None,
}
diff --git a/crates/screenpipe-engine/src/connections_api.rs b/crates/screenpipe-engine/src/connections_api.rs
index 04dc6b1d7..a8ade3e3e 100644
--- a/crates/screenpipe-engine/src/connections_api.rs
+++ b/crates/screenpipe-engine/src/connections_api.rs
@@ -1863,6 +1863,12 @@ fn resolve_auth(
ResolvedAuth::None
}
}
+ ProxyAuth::BasicAuthEmptyPassword { username_key } => creds
+ .and_then(|c| c.get(*username_key))
+ .and_then(Value::as_str)
+ .filter(|user| !user.is_empty())
+ .map(|user| ResolvedAuth::Basic(user.to_string(), String::new()))
+ .unwrap_or(ResolvedAuth::None),
ProxyAuth::None => ResolvedAuth::None,
}
}
@@ -3609,7 +3615,7 @@ mod calendar_error_response_tests {
#[cfg(test)]
mod tests {
use super::*;
- use screenpipe_connect::connections::{lexi::Lexi, Integration, ProxyAuth};
+ use screenpipe_connect::connections::{lexi::Lexi, mochi::Mochi, Integration, ProxyAuth};
use serde_json::json;
use axum::body::{to_bytes, Body};
@@ -4085,6 +4091,20 @@ mod tests {
}
}
+ #[test]
+ fn mochi_proxy_resolves_api_key_with_empty_password() {
+ let config = Mochi.proxy_config().expect("Mochi should support proxying");
+ let creds = Map::from_iter([("api_key".into(), json!("mochi-api-key"))]);
+
+ match resolve_auth(&config.auth, Some(&creds), None, None) {
+ ResolvedAuth::Basic(user, pass) => {
+ assert_eq!(user, "mochi-api-key");
+ assert!(pass.is_empty());
+ }
+ _ => panic!("expected Mochi API key to resolve with an empty Basic password"),
+ }
+ }
+
#[test]
fn leexi_proxy_resolves_complete_credentials_as_basic() {
let config = Lexi.proxy_config().expect("Leexi should support proxying");
@@ -4102,6 +4122,29 @@ mod tests {
}
}
+ #[test]
+ fn leexi_proxy_rejects_partial_or_empty_credentials() {
+ let config = Lexi.proxy_config().expect("Leexi should support proxying");
+
+ for creds in [
+ Map::from_iter([("api_key_id".into(), json!("key-id"))]),
+ Map::from_iter([("key_secret".into(), json!("key-secret"))]),
+ Map::from_iter([
+ ("api_key_id".into(), json!("")),
+ ("key_secret".into(), json!("key-secret")),
+ ]),
+ Map::from_iter([
+ ("api_key_id".into(), json!("key-id")),
+ ("key_secret".into(), json!("")),
+ ]),
+ ] {
+ assert!(matches!(
+ resolve_auth(&config.auth, Some(&creds), None, None),
+ ResolvedAuth::None
+ ));
+ }
+ }
+
#[test]
fn leexi_proxy_does_not_reinterpret_legacy_api_key() {
let config = Lexi.proxy_config().expect("Leexi should support proxying");