Skip to content

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

fix: require HTTPS for x402 payment requests

Steven Enamakelfff72b08eb50
diff --git a/crates/openhuman-core/src/web3/x402/seams.rs b/crates/openhuman-core/src/web3/x402/seams.rs
index 7ff8ed6f38..26c309e9d7 100644
--- a/crates/openhuman-core/src/web3/x402/seams.rs
+++ b/crates/openhuman-core/src/web3/x402/seams.rs
@@ -69,9 +69,16 @@ impl RequestGuard for HostRequestGuard {
"Action blocked: autonomy is read-only".into(),
));
}
- let host = reqwest::Url::parse(&request.url)
- .ok()
- .and_then(|parsed| parsed.host_str().map(str::to_string))
+ let parsed = reqwest::Url::parse(&request.url)
+ .map_err(|error| RequestAuthorizationError::InvalidDestination(error.to_string()))?;
+ if parsed.scheme() != "https" {
+ return Err(RequestAuthorizationError::InvalidDestination(
+ "x402 payment requests require HTTPS".into(),
+ ));
+ }
+ let host = 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(RequestAuthorizationError::Denied(
diff --git a/crates/openhuman-core/src/web3/x402/seams_tests.rs b/crates/openhuman-core/src/web3/x402/seams_tests.rs
index e5e5dcbdad..461f14db7a 100644
--- a/crates/openhuman-core/src/web3/x402/seams_tests.rs
+++ b/crates/openhuman-core/src/web3/x402/seams_tests.rs
@@ -220,6 +220,19 @@ async fn x402_guard_rejects_readonly_and_private_destinations() {
));
}
+#[tokio::test]
+async fn x402_guard_rejects_cleartext_payment_destinations() {
+ let _env_lock = crate::config::TEST_ENV_LOCK.lock().await;
+ let guard = HostRequestGuard {
+ security: Arc::new(SecurityPolicy::default()),
+ allowed_domains: vec![],
+ };
+ assert!(matches!(
+ guard.authorize(&proposed_request("http://8.8.8.8/")).await,
+ Err(RequestAuthorizationError::InvalidDestination(reason)) if reason.contains("HTTPS")
+ ));
+}
+
#[tokio::test]
async fn x402_rejected_destinations_do_not_exhaust_the_action_budget() {
let _env_lock = crate::config::TEST_ENV_LOCK.lock().await;
@@ -272,6 +285,13 @@ async fn x402_tool_runs_the_host_guard_before_network_or_payment() {
.unwrap();
assert!(blocked_domain.is_error);
assert!(blocked_domain.text().contains("[policy-blocked]"));
+
+ let blocked_cleartext = request_tool(Arc::new(SecurityPolicy::default()), vec![])
+ .execute(serde_json::json!({"url": "http://8.8.8.8:1/"}))
+ .await
+ .unwrap();
+ assert!(blocked_cleartext.is_error);
+ assert!(blocked_cleartext.text().contains("require HTTPS"));
}
#[tokio::test]