Skip to content

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

fix(client): disable automatic redirects in download and backend clients

Steven Enamakel798ec18f3a2c
diff --git a/crates/openhuman-core/src/integrations/client/construct.rs b/crates/openhuman-core/src/integrations/client/construct.rs
index 50511a3948..598cbce530 100644
--- a/crates/openhuman-core/src/integrations/client/construct.rs
+++ b/crates/openhuman-core/src/integrations/client/construct.rs
@@ -157,6 +157,7 @@ impl IntegrationClient {
.expect("failed to build integration download HTTP client");
let presigned_client = crate::util::tls::tls_client_builder()
.http1_only()
+ .redirect(reqwest::redirect::Policy::none())
.timeout(Duration::from_secs(15 * 60))
.connect_timeout(Duration::from_secs(15))
.build()
diff --git a/crates/openhuman-core/src/integrations/client/download.rs b/crates/openhuman-core/src/integrations/client/download.rs
index 5148c4be14..d1f0cec10c 100644
--- a/crates/openhuman-core/src/integrations/client/download.rs
+++ b/crates/openhuman-core/src/integrations/client/download.rs
@@ -73,7 +73,12 @@ impl IntegrationClient {
.send()
.await
.map_err(|error| Self::report_transport_error(error, "get_bytes", path, &url))?;
- if resp.status().is_redirection() {
+ // Follow redirects manually so every hop is checked. The authenticated
+ // first request is separate from the credential-free storage client.
+ for _ in 0..10 {
+ if !resp.status().is_redirection() {
+ break;
+ }
let location = resp
.headers()
.get(reqwest::header::LOCATION)
@@ -84,7 +89,7 @@ impl IntegrationClient {
crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(redirect_url.as_str()),
"download redirect requires HTTPS or a loopback HTTP endpoint"
);
- // The second request has no auth headers, including x-api-key.
+ // Redirect hops never carry backend headers, including x-api-key.
resp = self
.presigned_client
.get(redirect_url)
@@ -92,6 +97,10 @@ impl IntegrationClient {
.await
.map_err(|error| Self::report_transport_error(error, "get_bytes", path, &url))?;
}
+ anyhow::ensure!(
+ !resp.status().is_redirection(),
+ "download exceeded the maximum number of redirects"
+ );
let status = resp.status();
if !status.is_success() {
let body_text = resp.text().await.unwrap_or_default();
diff --git a/crates/openhuman-tinyhumans/src/backend/headers.rs b/crates/openhuman-tinyhumans/src/backend/headers.rs
index a4fd69df75..0acd74e471 100644
--- a/crates/openhuman-tinyhumans/src/backend/headers.rs
+++ b/crates/openhuman-tinyhumans/src/backend/headers.rs
@@ -89,6 +89,9 @@ pub fn backend_client_builder(profile: TransportProfile) -> Result<reqwest::Clie
Ok(openhuman_core::util::tls::tls_client_builder()
.default_headers(attribution_headers()?)
.http1_only()
+ // The SDK 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(timeout)
.connect_timeout(Duration::from_secs(15)))
}