Skip to content

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

fix(security): enforce live policy checks in the security gate

Steven Enamakel40948b17635d
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
index 479e700930..0e0103ae09 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
@@ -121,7 +121,7 @@ pub struct OpenHumanSecurityGate {
/// Fallback policy used when no process-global live policy is installed.
///
/// Per-call resolution prefers
- /// [`crate::security::live_policy::effective`] so an autonomy
+ /// [`crate::security::live_policy::effective_in`] so an autonomy
/// change made mid-session is observed on the very next tool call — the
/// same live-first / snapshot-fallback discipline `ApprovalGate` uses for
/// `auto_approve`. The trait explicitly forbids the runtime caching a
diff --git a/crates/openhuman-core/src/profiles/host_tests.rs b/crates/openhuman-core/src/profiles/host_tests.rs
index e5864c16dd..8763083d4d 100644
--- a/crates/openhuman-core/src/profiles/host_tests.rs
+++ b/crates/openhuman-core/src/profiles/host_tests.rs
@@ -317,7 +317,7 @@ async fn an_open_profile_is_gated_by_its_own_policy_not_the_operators() {
assert!(own.enabled, "the forced autonomy policy is on");
assert!(own.workspace_only);
let effective = CoreContext::scope(Arc::clone(state.context()), async {
- crate::security::live_policy::effective()
+ crate::security::live_policy::effective_in(&crate::core::runtime::DispatchCtx::ambient())
})
.await
.expect("a policy is in effect");
diff --git a/crates/openhuman-core/src/security/devices/bus.rs b/crates/openhuman-core/src/security/devices/bus.rs
index fe5a8dddad..68e8cbf515 100644
--- a/crates/openhuman-core/src/security/devices/bus.rs
+++ b/crates/openhuman-core/src/security/devices/bus.rs
@@ -95,13 +95,12 @@ impl EventHandler<DomainEvent> for DeviceTunnelSubscriber {
.unwrap_or_else(std::sync::PoisonError::into_inner)
.get(channel_id.as_str())
.cloned();
- match super::owner::owner_of(&DispatchCtx::ambient(), channel_id, pending.as_ref())
- .await
- {
+ let ctx = DispatchCtx::ambient();
+ match super::owner::owner_of(&ctx, channel_id, pending.as_ref()).await {
Ok(owner) => {
let handled = crate::storage::agents::within_agent(
owner.as_deref(),
- handle_tunnel_frame(&DispatchCtx::ambient(), channel_id, payload_b64),
+ handle_tunnel_frame(&ctx, channel_id, payload_b64),
)
.await;
// Fail closed: no context can act for the owner.
diff --git a/crates/openhuman-core/src/security/live_policy.rs b/crates/openhuman-core/src/security/live_policy.rs
index 75a993a2e3..707e0de0e4 100644
--- a/crates/openhuman-core/src/security/live_policy.rs
+++ b/crates/openhuman-core/src/security/live_policy.rs
@@ -175,16 +175,8 @@ pub fn current() -> Option<Arc<SecurityPolicy>> {
.and_then(|s| s.policy.read().ok().map(|g| Arc::clone(&g)))
}
-/// The policy a call should be answered against: the ambient agent context's
-/// own policy when it carries one, else the process-global [`current`] policy.
-///
-/// Reads the calling task's ambient context; a caller that holds its own
-/// context uses [`effective_in`].
-pub fn effective() -> Option<Arc<SecurityPolicy>> {
- effective_in(&crate::core::runtime::DispatchCtx::ambient())
-}
-
-/// [`effective`] for the agent `ctx` runs for.
+/// The policy a call should be answered against: `ctx`'s agent's own policy
+/// when it carries one, else the process-global [`current`] policy.
pub fn effective_in(ctx: &crate::core::runtime::DispatchCtx) -> Option<Arc<SecurityPolicy>> {
if let Some(policy) = ctx.agent_policy() {
return Some(policy);
diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs
index 436cc9edbd..b0cdc75dd8 100644
--- a/crates/openhuman-core/src/security/live_policy_tests.rs
+++ b/crates/openhuman-core/src/security/live_policy_tests.rs
@@ -232,3 +232,8 @@ async fn effective_falls_back_to_the_process_policy_for_an_agent_without_one() {
crate::core::runtime::CoreContext::scope(agent_context(None), async { effective() }).await;
assert!(Arc::ptr_eq(&seen.expect("process policy"), &process));
}
+
+/// The policy in effect for the calling task's ambient context.
+fn effective() -> Option<Arc<SecurityPolicy>> {
+ effective_in(&crate::core::runtime::DispatchCtx::ambient())
+}