The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(hosted): refuse credential endpoints before HostedClient sends anything
M3gA-Mind07d638d3050d
diff --git a/crates/openhuman-tinyhumans/src/doctor/mod.rs b/crates/openhuman-tinyhumans/src/doctor/mod.rsindex c0f9c4ae4d..e9a19801b1 100644--- a/crates/openhuman-tinyhumans/src/doctor/mod.rs+++ b/crates/openhuman-tinyhumans/src/doctor/mod.rs@@ -203,8 +203,10 @@ impl DoctorCheck for BackendIdentity {if health_check(ctx.config()).await.is_err() {return vec![backend_dependent_skipped(self.id())];}-- let client = hosted_client(ctx.config(), credential);+ let client = match hosted_client(ctx.config(), credential) {+ Ok(client) => client,+ Err(reason) => return vec![endpoint_refused(self.id(), &reason)],+ };vec![match client.sdk().auth().me().await {Ok(_) => Finding::pass(self.id(), "The backend accepted the configured identity."),Err(error) => auth_finding(self.id(), client.kind(), error, AUTH_FIX),@@ -385,8 +387,10 @@ impl DoctorCheck for ManagedCatalog {if health_check(ctx.config()).await.is_err() {return vec![backend_dependent_skipped(self.id())];}-- let client = hosted_client(ctx.config(), credential);+ let client = match hosted_client(ctx.config(), credential) {+ Ok(client) => client,+ Err(reason) => return vec![endpoint_refused(self.id(), &reason)],+ };let query = [("catalog", Some("openrouter".to_owned()))];vec![match client.sdk().inference().list_models(&query).await {Ok(_) => Finding::pass(self.id(), "The managed inference catalog is reachable."),@@ -431,10 +435,18 @@ fn doctor_credential(config: &Config) -> CredentialState {}}-fn hosted_client(config: &Config, credential: BackendCredential) -> HostedClient {+fn hosted_client(config: &Config, credential: BackendCredential) -> Result<HostedClient, String> {HostedClient::with_credential(&effective_backend_api_url(&config.api_url), credential)}+fn endpoint_refused(id: &str, reason: &str) -> Finding {+ Finding::error(+ id,+ format!("The hosted credential was not sent: {reason}."),+ "Point the API URL at the managed backend over HTTPS, or at a loopback endpoint for local testing.",+ )+}+fn credential_skipped(id: &str) -> Finding {Finding::skipped(id,diff --git a/crates/openhuman-tinyhumans/src/hosted/announcements/ops_tests.rs b/crates/openhuman-tinyhumans/src/hosted/announcements/ops_tests.rsindex 1641866ff9..cc329af66e 100644--- a/crates/openhuman-tinyhumans/src/hosted/announcements/ops_tests.rs+++ b/crates/openhuman-tinyhumans/src/hosted/announcements/ops_tests.rs@@ -22,7 +22,8 @@ fn only_a_404_status_counts_as_not_found() {async fn latest_via(server: &MockServer) -> Result<Option<Value>, String> {let client =- HostedClient::with_credential(&server.uri(), BackendCredential::Session("jwt".into()));+ HostedClient::with_credential(&server.uri(), BackendCredential::Session("jwt".into()))+ .expect("loopback endpoint");let result = client.sdk().announcements()diff --git a/crates/openhuman-tinyhumans/src/hosted/client.rs b/crates/openhuman-tinyhumans/src/hosted/client.rsindex e6d170a9c9..ccd70dc76b 100644--- a/crates/openhuman-tinyhumans/src/hosted/client.rs+++ b/crates/openhuman-tinyhumans/src/hosted/client.rs@@ -69,18 +69,28 @@ impl HostedClient {})?;require_transport()?;let base_url = backend_origin(&effective_backend_api_url(&config.api_url))?;- Ok(Self::with_credential(&base_url, credential))+ Self::with_credential(&base_url, credential)}/// Build the client against `base_url` for an already-resolved credential.- pub fn with_credential(base_url: &str, credential: BackendCredential) -> Self {+ ///+ /// Refuses, without network I/O, an endpoint the credential may not be+ /// sent to: an API key only to the managed hosts or loopback, and any+ /// credential only over HTTPS or loopback HTTP — the guard `BackendClient`+ /// and `IntegrationsHttp` already apply.+ pub fn with_credential(base_url: &str, credential: BackendCredential) -> Result<Self, String> {+ crate::client::endpoint::validate_credential_endpoint(+ base_url,+ matches!(credential, BackendCredential::ApiKey(_)),+ )+ .map_err(|err| err.to_string())?;let sdk = TinyHumansClient::new(base_url).with_http_client(http_client())// The product identity (`x-sdk-name`) also rides the SDK's own// default headers, exactly as the SDK transport does, so it holds// even for a client this crate did not build..with_default_headers(crate::backend::product::product_identity_headers());- match credential {+ Ok(match credential {BackendCredential::Session(secret) => Self {sdk: sdk.with_token(Some(secret.trim().to_string())),kind: CredentialKind::Session,@@ -89,7 +99,7 @@ impl HostedClient {sdk: sdk.with_api_key(Some(secret.trim().to_string())),kind: CredentialKind::ApiKey,},- }+ })}/// The typed SDK client.diff --git a/crates/openhuman-tinyhumans/src/hosted/client_tests.rs b/crates/openhuman-tinyhumans/src/hosted/client_tests.rsindex eba12173fe..e0685d8885 100644--- a/crates/openhuman-tinyhumans/src/hosted/client_tests.rs+++ b/crates/openhuman-tinyhumans/src/hosted/client_tests.rs@@ -164,6 +164,7 @@ async fn session_client_sends_bearer_and_product_identity() {let _identity = crate::backend::product::product_identity_test_lock();crate::backend::product::reset_product_identity_for_test();HostedClient::with_credential(&server.uri(), BackendCredential::Session("jwt.a.b".into()))+ .expect("loopback endpoint")};assert_eq!(client.kind(), CredentialKind::Session);let value = client@@ -187,7 +188,8 @@ async fn api_key_client_sends_x_api_key_and_maps_401() {.await;let client =- HostedClient::with_credential(&server.uri(), BackendCredential::ApiKey("th_key".into()));+ HostedClient::with_credential(&server.uri(), BackendCredential::ApiKey("th_key".into()))+ .expect("loopback endpoint");let err = client.finish_value("GET /teams/me/usage",@@ -196,3 +198,17 @@ async fn api_key_client_sends_x_api_key_and_maps_401() {.unwrap_err();assert!(is_api_key_rejected_message(&err), "{err}");}++#[test]+fn with_credential_refuses_endpoints_the_credential_may_not_reach() {+ let api_key = || BackendCredential::ApiKey("th_key".into());+ let session = || BackendCredential::Session("jwt.a.b".into());+ // An API key belongs to TinyHumans: managed hosts or loopback only.+ assert!(HostedClient::with_credential("https://not-tinyhumans.example", api_key()).is_err());+ assert!(HostedClient::with_credential("https://api.tinyhumans.ai", api_key()).is_ok());+ assert!(HostedClient::with_credential("http://127.0.0.1:7788", api_key()).is_ok());+ // Any credential: HTTPS, or plain HTTP only to loopback.+ assert!(HostedClient::with_credential("http://192.168.1.5:8080", session()).is_err());+ assert!(HostedClient::with_credential("https://backend.example", session()).is_ok());+ assert!(HostedClient::with_credential("http://localhost:7788", session()).is_ok());+}