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: apply host network policy to x402 tool
Steven Enamakel6c1a5bb7bad5
diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rsindex c9fd28c65f..20e485e587 100644--- a/crates/openhuman-core/src/tools/ops.rs+++ b/crates/openhuman-core/src/tools/ops.rs@@ -632,7 +632,10 @@ pub fn all_tools_with_runtime(// or SPL payment signing, and ledger recording. Gated with the `web3`// feature (the x402 domain is compiled out when web3 is disabled).#[cfg(feature = "web3")]- tools.push(Box::new(crate::web3::x402::request_tool()));+ tools.push(Box::new(crate::web3::x402::request_tool(+ security.clone(),+ http_config.allowed_domains.clone(),+ )));// Coding-harness baseline `web_fetch` (issue #1205) — single-purpose// GET-and-read primitive that reuses the same allowed-domains gatediff --git a/crates/openhuman-core/src/web3/x402/mod.rs b/crates/openhuman-core/src/web3/x402/mod.rsindex b0c45214b1..1e9736f8f5 100644--- a/crates/openhuman-core/src/web3/x402/mod.rs+++ b/crates/openhuman-core/src/web3/x402/mod.rs@@ -48,7 +48,7 @@ pub use schemas::all_registered_controllers as all_x402_registered_controllers;#[cfg(feature = "web3")]pub use tinywallet_x402::ledger::{PaymentRecord, PaymentStatus, SpendingBudget};#[cfg(feature = "web3")]-pub use tinywallet_x402::protocol::{handle_402, X402Client, X402Error, X402PaymentResult};+pub use tinywallet_x402::protocol::{X402Client, X402Error, X402PaymentResult, handle_402};#[cfg(feature = "web3")]pub use tinywallet_x402::wire::{EvmAuthorization, EvmPaymentProof, PaymentChain, PaymentPayload, PaymentProof, PaymentRequired,@@ -82,10 +82,14 @@ pub async fn handle_402_and_pay(}/// The `x402_request` agent tool, wired to OpenHuman's wallet, chain-/// transport and proxy policy.+/// transport, proxy and network policy. `allowed_domains` is the same list+/// passed to the other agent network tools.#[cfg(feature = "web3")]-pub fn request_tool() -> tinywallet_x402::tools::X402RequestTool {- seams::request_tool()+pub fn request_tool(+ security: std::sync::Arc<crate::security::SecurityPolicy>,+ allowed_domains: Vec<String>,+) -> tinywallet_x402::tools::X402RequestTool {+ seams::request_tool(security, allowed_domains)}// ---------------------------------------------------------------------------diff --git a/crates/openhuman-core/src/web3/x402/seams.rs b/crates/openhuman-core/src/web3/x402/seams.rsindex 4f72de9ce4..3382c64f7c 100644--- a/crates/openhuman-core/src/web3/x402/seams.rs+++ b/crates/openhuman-core/src/web3/x402/seams.rs@@ -23,15 +23,18 @@ use std::sync::Arc;use async_trait::async_trait;use log::debug;+use tinytools_std::network::NetGate;+use tinytools_std::url_guard::validate_url_with_dns_check;use tinywallet_x402::crypto::{CryptoPayments, PaymentAccount, PaymentSigner, SignScheme};use tinywallet_x402::protocol::ProxyPolicy;use tinywallet_x402::thread::ThreadScope;-use tinywallet_x402::tools::X402RequestTool;+use tinywallet_x402::tools::{AuthorizedUrl, RequestGuard, X402RequestTool};use tinywallet_x402::wire::PaymentChain;+use crate::security::SecurityPolicy;use crate::security::approval::APPROVAL_CHAT_CONTEXT;-use crate::web3::wallet::transport::OpenHumanTransport;use crate::web3::wallet::WalletChain;+use crate::web3::wallet::transport::OpenHumanTransport;const LOG_PREFIX: &str = "[x402::seams]";@@ -43,6 +46,49 @@ pub(crate) struct WalletPaymentSigner;#[derive(Debug, Clone, Copy, Default)]pub(crate) struct RuntimeProxyPolicy;+#[derive(Debug)]+pub(crate) struct HostRequestGuard {+ security: Arc<SecurityPolicy>,+ allowed_domains: Vec<String>,+}++#[async_trait]+impl RequestGuard for HostRequestGuard {+ fn needs_approval(&self) -> bool {+ self.security.network_needs_approval()+ }++ async fn authorize(+ &self,+ url: &str,+ has_body: bool,+ has_headers: bool,+ ) -> Result<AuthorizedUrl, String> {+ if !self.security.can_act() {+ return Err("[policy-blocked] Action blocked: autonomy is read-only".into());+ }+ if !self.security.record_action() {+ return Err("Action blocked: rate limit exceeded".into());+ }+ let host = reqwest::Url::parse(url)+ .ok()+ .and_then(|parsed| parsed.host_str().map(str::to_string))+ .unwrap_or_else(|| "unknown".to_string());+ if let Some(reason) = self.security.local_only_block(&host) {+ return Err(reason);+ }+ let target = validate_url_with_dns_check(url, &self.allowed_domains)+ .await+ .map_err(|error| error.to_string())?;+ self.security.disclose(&target.host, has_body, has_headers);+ Ok(AuthorizedUrl {+ url: target.url,+ host: target.host,+ addrs: target.addrs,+ })+ }+}+/// The chat thread running the current tool call, read from/// `APPROVAL_CHAT_CONTEXT`.///@@ -198,13 +244,20 @@ pub(crate) fn payments() -> CryptoPayments {}/// The `x402_request` tool, over the same seams.-pub(crate) fn request_tool() -> X402RequestTool {+pub(crate) fn request_tool(+ security: Arc<SecurityPolicy>,+ allowed_domains: Vec<String>,+) -> X402RequestTool {X402RequestTool::new(Arc::new(WalletPaymentSigner),Arc::new(OpenHumanTransport::new()),Arc::new(RuntimeProxyPolicy),).with_thread_scope(Arc::new(TaskLocalThread))+ .with_request_guard(Arc::new(HostRequestGuard {+ security,+ allowed_domains,+ }))}#[cfg(test)]diff --git a/crates/openhuman-core/src/web3/x402/seams_tests.rs b/crates/openhuman-core/src/web3/x402/seams_tests.rsindex 5ace6a11d7..6654de4918 100644--- a/crates/openhuman-core/src/web3/x402/seams_tests.rs+++ b/crates/openhuman-core/src/web3/x402/seams_tests.rs@@ -86,8 +86,15 @@ fn the_proxy_policy_yields_a_buildable_client() {#[test]fn the_tool_is_built_from_the_host_seams() {use tinytools::Tool;- assert_eq!(request_tool().name(), "x402_request");- assert_eq!(super::super::request_tool().name(), "x402_request");+ let security = Arc::new(SecurityPolicy::default());+ assert_eq!(+ request_tool(security.clone(), vec![]).name(),+ "x402_request"+ );+ assert_eq!(+ super::super::request_tool(security, vec![]).name(),+ "x402_request"+ );}fn solana_challenge_headers() -> HeaderMap {diff --git a/vendor/tinywallet b/vendor/tinywalletindex b53917764e..219d9ab170 160000--- a/vendor/tinywallet+++ b/vendor/tinywallet@@ -1 +1 @@-Subproject commit b53917764e08d90abdc1403ac40e74fc552530e2+Subproject commit 219d9ab1707b973f1ee76b9d2ba1c92a9b64d6ff