Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(session): do not follow redirects from the session client

M3gA-Mind8ab33215a185
diff --git a/crates/openhuman-tinyhumans/src/session/client.rs b/crates/openhuman-tinyhumans/src/session/client.rs
index ee04a67685..48a647eb6d 100644
--- a/crates/openhuman-tinyhumans/src/session/client.rs
+++ b/crates/openhuman-tinyhumans/src/session/client.rs
@@ -264,6 +264,9 @@ impl SessionClient {
let http = openhuman_embed::__host::util::tls::tls_client_builder()
.http1_only()
+ // `sdk_with` adds `x-api-key` per request. Reqwest does not strip
+ // this custom header when following a cross-origin redirect.
+ .redirect(reqwest::redirect::Policy::none())
.timeout(REQUEST_TIMEOUT)
.connect_timeout(CONNECT_TIMEOUT)
.default_headers(headers.header_map())
diff --git a/crates/openhuman-tinyhumans/src/session/client_tests.rs b/crates/openhuman-tinyhumans/src/session/client_tests.rs
index fa142dfffd..3e69075f87 100644
--- a/crates/openhuman-tinyhumans/src/session/client_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/client_tests.rs
@@ -187,3 +187,33 @@ async fn validation_budget_honours_new_then_legacy_env() {
std::env::remove_var(VALIDATION_BUDGET_ENV);
std::env::remove_var(LEGACY_VALIDATION_BUDGET_ENV);
}
+
+#[tokio::test]
+async fn fetch_me_does_not_follow_a_cross_origin_redirect_with_the_api_key() {
+ use wiremock::matchers::any;
+ use wiremock::{Mock, MockServer, ResponseTemplate};
+
+ let elsewhere = MockServer::start().await;
+ Mock::given(any())
+ .respond_with(ResponseTemplate::new(200).set_body_json(me_user()))
+ .mount(&elsewhere)
+ .await;
+ let backend = MockServer::start().await;
+ Mock::given(any())
+ .respond_with(
+ ResponseTemplate::new(302)
+ .insert_header("location", format!("{}/auth/me", elsewhere.uri())),
+ )
+ .mount(&backend)
+ .await;
+
+ let client = SessionClient::new(&backend.uri(), &headers()).unwrap();
+ let _ = client.fetch_me(&Credential::api_key("sk-1")).await;
+
+ assert_eq!(backend.received_requests().await.unwrap().len(), 1);
+ let leaked = elsewhere.received_requests().await.unwrap();
+ assert!(
+ leaked.iter().all(|r| !r.headers.contains_key("x-api-key")),
+ "the redirect target received the API key"
+ );
+}