Skip to content

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

fix(x402): normalize host domain allowlists

Steven Enamakeld10aa6440a05
diff --git a/crates/openhuman-core/src/web3/x402/seams.rs b/crates/openhuman-core/src/web3/x402/seams.rs
index b1998a75e5..cbded5618d 100644
--- a/crates/openhuman-core/src/web3/x402/seams.rs
+++ b/crates/openhuman-core/src/web3/x402/seams.rs
@@ -24,7 +24,7 @@ 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 tinytools_std::url_guard::{normalize_allowed_domains, validate_url_with_dns_check};
use tinywallet_x402::crypto::{CryptoPayments, PaymentAccount, PaymentSigner, SignScheme};
use tinywallet_x402::protocol::ProxyPolicy;
use tinywallet_x402::thread::ThreadScope;
@@ -300,10 +300,17 @@ pub(crate) fn request_tool(
Arc::new(RuntimeProxyPolicy),
)
.with_thread_scope(Arc::new(TaskLocalThread))
- .with_request_guard(Arc::new(HostRequestGuard {
+ .with_request_guard(Arc::new(host_request_guard(security, allowed_domains)))
+}
+
+fn host_request_guard(
+ security: Arc<SecurityPolicy>,
+ allowed_domains: Vec<String>,
+) -> HostRequestGuard {
+ HostRequestGuard {
security,
- allowed_domains,
- }))
+ allowed_domains: normalize_allowed_domains(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.rs
index 1421b982ec..952914e818 100644
--- a/crates/openhuman-core/src/web3/x402/seams_tests.rs
+++ b/crates/openhuman-core/src/web3/x402/seams_tests.rs
@@ -223,6 +223,24 @@ async fn x402_tool_runs_the_host_guard_before_network_or_payment() {
assert!(blocked_domain.text().contains("[policy-blocked]"));
}
+#[tokio::test]
+async fn x402_host_guard_normalizes_the_network_allowlist() {
+ let security = Arc::new(SecurityPolicy::default());
+ let allowed = host_request_guard(security.clone(), vec!["HTTPS://8.8.8.8/path".into()]);
+ assert!(allowed
+ .authorize(&proposed_request("https://8.8.8.8/"))
+ .await
+ .is_ok());
+
+ let malformed = host_request_guard(security, vec![" ".into()]);
+ assert!(matches!(
+ malformed
+ .authorize(&proposed_request("https://8.8.8.8/"))
+ .await,
+ Err(RequestAuthorizationError::InvalidDestination(_))
+ ));
+}
+
#[test]
fn the_tool_is_built_from_the_host_seams() {
use tinytools::Tool;