Skip to content

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

feat(api-key): restrict TinyHumans API key to managed endpoints

Steven Enamakela2207048330e
diff --git a/crates/openhuman-core/src/backend/client.rs b/crates/openhuman-core/src/backend/client.rs
index 651e76cb1f..cef6ff160c 100644
--- a/crates/openhuman-core/src/backend/client.rs
+++ b/crates/openhuman-core/src/backend/client.rs
@@ -418,9 +418,10 @@ impl BackendClient {
) -> Result<Value> {
let credential = credential.into();
let is_api_key = credential.is_api_key();
- if !crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(
- self.base.as_str(),
- ) {
+ if is_api_key && !crate::inference::provider::openhuman_backend_model::is_managed_endpoint_for_api_key(self.base.as_str()) {
+ anyhow::bail!("TinyHumans API key requires the managed backend or a loopback endpoint");
+ }
+ if !crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(self.base.as_str()) {
anyhow::bail!("backend credential requires HTTPS or a loopback HTTP endpoint");
}
let transport = self.transport(&method, path)?;
diff --git a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs
index 60bba12b57..4c44b746b6 100644
--- a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs
@@ -50,7 +50,7 @@ impl OpenHumanCloudEmbeddingModel {
crate::security::credentials::api_key::get_api_key_in(&state_dir, secrets_encrypt)
.map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?
{
- if !crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(
+ if !crate::inference::provider::openhuman_backend_model::is_managed_endpoint_for_api_key(
&key_endpoint,
) {
return Err(tinyinference_embeddings::Error::Validation(format!(
diff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs
index edc4c21da4..a11250a933 100644
--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs
+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs
@@ -69,6 +69,20 @@ pub(crate) fn is_safe_endpoint_for_managed_bearer(endpoint: &str) -> bool {
) || host.starts_with("127.")
}
+/// API keys belong to TinyHumans. A loopback endpoint is permitted for local
+/// development; an arbitrary TLS host is not a trusted key recipient.
+pub(crate) fn is_managed_endpoint_for_api_key(endpoint: &str) -> bool {
+ let Ok(url) = url::Url::parse(endpoint) else {
+ return false;
+ };
+ if !is_safe_endpoint_for_managed_bearer(endpoint) {
+ return false;
+ }
+ matches!(url.host_str(), Some("api.tinyhumans.ai" | "staging-api.tinyhumans.ai"))
+ && url.scheme() == "https"
+ || matches!(url.host_str(), Some("localhost" | "127.0.0.1" | "::1"))
+}
+
/// The managed OpenHuman backend as a crate [`ChatModel`]. Holds the backend
/// connection settings (for JWT + base-URL resolution) and the default model id
/// sent when a request doesn't override it.
@@ -168,7 +182,7 @@ impl OpenHumanBackendModel {
// plain HTTP on loopback), so this cannot tighten
// `normalize_api_base_url` itself without breaking those.
let endpoint = self.base_url()?;
- if !is_safe_endpoint_for_managed_bearer(&endpoint) {
+ if !is_managed_endpoint_for_api_key(&endpoint) {
anyhow::bail!(
"refusing to send the TinyHumans API key as a bearer over a non-HTTPS, \
non-loopback endpoint: {endpoint} — set a https:// api_url or a loopback \
diff --git a/crates/openhuman-core/src/voice/cloud_transcribe.rs b/crates/openhuman-core/src/voice/cloud_transcribe.rs
index 6ba187c43b..796c80a6d6 100644
--- a/crates/openhuman-core/src/voice/cloud_transcribe.rs
+++ b/crates/openhuman-core/src/voice/cloud_transcribe.rs
@@ -22,7 +22,7 @@ pub async fn transcribe_cloud(
.url_for("/openai/v1/audio/transcriptions")
.map_err(|error| error.to_string())?;
if is_api_key
- && !crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(
+ && !crate::inference::provider::openhuman_backend_model::is_managed_endpoint_for_api_key(
url.as_str(),
)
{