Skip to content

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

fix(inference): never send the session JWT to a plaintext remote endpoint

M3gA-Mind8a9eef638830
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs b/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
index 64cd0d0be0..85af15f2cd 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
@@ -103,6 +103,7 @@ fn build_cloud_model(
return Ok(key);
}
resolve_session_bearer(
+ &key_endpoint,
&state_dir,
secrets_encrypt,
None,
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_model.rs b/crates/openhuman-tinyhumans/src/inference/managed_model.rs
index 5e45756458..3b2fd3db92 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_model.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_model.rs
@@ -55,6 +55,7 @@ impl ManagedOptions {
return Ok(key);
}
resolve_session_bearer(
+ endpoint,
&self.state_dir(),
self.secrets_encrypt,
self.auth_profile_override.as_deref(),
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_model_tests.rs b/crates/openhuman-tinyhumans/src/inference/managed_model_tests.rs
index 7d54e78fa7..c95507cc17 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_model_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_model_tests.rs
@@ -168,6 +168,24 @@ fn managed_bearer_resolves_a_future_expiry_app_session() {
);
}
+#[test]
+fn managed_session_bearer_refuses_a_plaintext_remote_endpoint() {
+ let tmp = tempfile::TempDir::new().expect("temporary credentials");
+ seed_app_session(tmp.path(), Some("2999-01-01T00:00:00Z"));
+ let options = managed_options_at(tmp.path());
+
+ let error = options
+ .resolve_bearer("http://10.0.0.1:1/openai/v1")
+ .expect_err("plaintext remote endpoint must not receive the session token");
+ assert!(error.to_string().contains("insecure endpoint"), "{error}");
+ assert_eq!(
+ options
+ .resolve_bearer("https://api.example.test/openai/v1")
+ .expect("HTTPS stays allowed"),
+ "test.session.jwt"
+ );
+}
+
#[test]
fn managed_bearer_resolves_exp_less_hosted_app_sessions() {
let tmp = tempfile::TempDir::new().expect("temporary credentials");
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_session.rs b/crates/openhuman-tinyhumans/src/inference/managed_session.rs
index 5e9a26db88..8d9c17e808 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_session.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_session.rs
@@ -9,8 +9,10 @@ use tinyinference_llm::providers::tinyhumans::{
/// Resolve the persisted app-session token for a managed inference caller.
/// Both chat and embeddings use this path so signed-out state, expiry checks,
-/// and offline-local credential refusal stay consistent.
+/// offline-local credential refusal, and the plaintext-endpoint refusal stay
+/// consistent.
pub(super) fn resolve_session_bearer(
+ endpoint: &str,
state_dir: &std::path::Path,
secrets_encrypt: bool,
profile_override: Option<&str>,
@@ -19,6 +21,7 @@ pub(super) fn resolve_session_bearer(
use openhuman_embed::__host::security::credentials::session_support::classify_session_token;
use openhuman_embed::__host::security::credentials::{AuthService, APP_SESSION_PROVIDER};
+ ensure_session_endpoint(endpoint)?;
if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
anyhow::bail!("SESSION_EXPIRED: backend session not active — sign in to resume LLM work");
}
@@ -39,14 +42,14 @@ pub(super) fn managed_bearer_for_inspection(
load_app_session_profile_read_only, SessionTokenCheck,
};
+ let endpoint = format!(
+ "{}/openai/v1",
+ crate::backend::url::effective_api_url(&config.api_url).trim_end_matches('/')
+ );
if let Some(key) =
openhuman_embed::__host::security::credentials::api_key::get_api_key_read_only(config)
.map_err(|_| anyhow::anyhow!("managed API key profile is unavailable or invalid"))?
{
- let endpoint = format!(
- "{}/openai/v1",
- crate::backend::url::effective_api_url(&config.api_url).trim_end_matches('/')
- );
anyhow::ensure!(
crate::client::endpoint::is_managed_endpoint_for_api_key(&endpoint),
"managed API key endpoint is not an approved managed endpoint"
@@ -54,6 +57,7 @@ pub(super) fn managed_bearer_for_inspection(
return Ok(key);
}
+ ensure_session_endpoint(&endpoint)?;
let profile = load_app_session_profile_read_only(config)
.map_err(|_| anyhow::anyhow!("managed session profile is unavailable or invalid"))?;
check_session_backend(config, profile.as_ref())
@@ -68,6 +72,18 @@ pub(super) fn managed_bearer_for_inspection(
}
}
+/// Refuse to put the session JWT on a plaintext wire: HTTPS, or HTTP only to
+/// loopback — the same rule every other backend credential caller applies.
+fn ensure_session_endpoint(endpoint: &str) -> anyhow::Result<()> {
+ anyhow::ensure!(
+ crate::client::endpoint::is_safe_endpoint_for_managed_bearer(endpoint),
+ "refusing to send the TinyHumans session token to an insecure endpoint: {} — \
+ use HTTPS, or HTTP only to loopback",
+ super::managed_model::endpoint_origin_for_log(endpoint)
+ );
+ Ok(())
+}
+
/// The bearer a classified app-session token yields for managed inference.
///
/// Separate from the model factory's bearer resolver so the decision is
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs b/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
index eea6022878..c9ecb15f75 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
@@ -54,6 +54,41 @@ fn a_signed_in_session_still_authenticates_managed_inference() {
assert_eq!(bearer, "header.payload.signature");
}
+#[test]
+fn inspection_refuses_the_session_token_on_a_plaintext_remote_endpoint() {
+ use openhuman_embed::__host::config::Config;
+
+ let temp = tempfile::tempdir().expect("temporary selected credential workspace");
+ std::fs::write(
+ temp.path().join("auth-profiles.json"),
+ r#"{"schema_version":1,"active_profiles":{"app-session":"app-session:default"},"profiles":{"app-session:default":{"provider":"app-session","profile_name":"default","kind":"token","token":"inspection-session-token"}}}"#,
+ )
+ .expect("seed selected app-session profile");
+ let config_for = |api_url: &str| Config {
+ workspace_dir: temp.path().to_owned(),
+ action_dir: temp.path().to_owned(),
+ config_path: temp.path().join("config.toml"),
+ api_url: Some(api_url.to_owned()),
+ secrets: {
+ let mut secrets = Config::default().secrets;
+ secrets.encrypt = false;
+ secrets
+ },
+ ..Config::default()
+ };
+
+ let error = managed_bearer_for_inspection(&config_for("http://10.0.0.1:1"))
+ .expect_err("plaintext remote endpoint must not receive the session token");
+ assert!(error.to_string().contains("insecure endpoint"), "{error}");
+ assert!(!error.to_string().contains("inspection-session-token"));
+
+ assert_eq!(
+ managed_bearer_for_inspection(&config_for("http://127.0.0.1:1"))
+ .expect("loopback HTTP stays allowed"),
+ "inspection-session-token"
+ );
+}
+
static SESSION_EXPIRY_EVENT_TEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
#[tokio::test]