Skip to content

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

fix(storage): reject unrelayed document watches in callback endpoint

Steven Enamakel826fe3c3940f
diff --git a/crates/openhuman-core/src/modules/storage_host_invocation.rs b/crates/openhuman-core/src/modules/storage_host_invocation.rs
index f0c9705204..881134aeb0 100644
--- a/crates/openhuman-core/src/modules/storage_host_invocation.rs
+++ b/crates/openhuman-core/src/modules/storage_host_invocation.rs
@@ -168,17 +168,29 @@ impl StorageEndpoint for DocumentsOnlyEndpoint {
.map_err(|denied| HostFailure::Denied(denied.label()))?;
match plan {
Plan::Answer(reply) => Ok(reply),
- Plan::Forward { filter, .. } => self
- .server
- .handle(
+ Plan::Forward { filter, .. } => {
+ if matches!(call.selector, "WatchOpen" | "WatchClose") {
+ return Err(Self::unsupported());
+ }
+ let mut reply = self
+ .server
+ .handle(
Admission::Private,
Object::Documents.as_str(),
call.selector,
call.request,
)
.await
- .map(|reply| storage_grants::filter_reply(&self.grant, filter, reply))
- .map_err(HostFailure::Storage),
+ .map_err(HostFailure::Storage)?;
+ if call.selector == "Capabilities"
+ && let Some(capabilities) = reply
+ .get_mut("capabilities")
+ .and_then(Value::as_array_mut)
+ {
+ capabilities.retain(|capability| capability.as_str() != Some("watch"));
+ }
+ Ok(storage_grants::filter_reply(&self.grant, filter, reply))
+ }
}
}
(Object::Streams, "Capabilities") => Ok(json!(CapabilitiesReply::default())),
diff --git a/crates/openhuman-core/src/modules/storage_host_invocation_tests.rs b/crates/openhuman-core/src/modules/storage_host_invocation_tests.rs
index e7b2b6c6fe..97a0c6d7c1 100644
--- a/crates/openhuman-core/src/modules/storage_host_invocation_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_invocation_tests.rs
@@ -133,6 +133,41 @@ async fn callback_documents_route_keeps_the_module_collection_grant() {
);
}
+#[tokio::test]
+async fn callback_documents_route_does_not_advertise_or_open_unrelayed_watches() {
+ let (endpoint, peer) = endpoint();
+
+ let capabilities = call(
+ &endpoint,
+ Some(&peer),
+ Object::Documents,
+ "Capabilities",
+ json!(null),
+ )
+ .await
+ .unwrap();
+ assert!(!capabilities["capabilities"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .any(|capability| capability == "watch"));
+ assert_eq!(
+ call(
+ &endpoint,
+ Some(&peer),
+ Object::Documents,
+ "WatchOpen",
+ json!({
+ "collection": "juice.savings",
+ "filter": {"kind": "all"},
+ "interval_ms": 10
+ }),
+ )
+ .await,
+ Err(DocumentsOnlyEndpoint::unsupported())
+ );
+}
+
#[tokio::test]
async fn dropped_invocation_refuses_calls_already_in_flight_at_endpoint() {
let (endpoint, peer) = endpoint();