Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(server): secure watch task refreshes (#3855)

Qin Haojie21029f40f3b4
diff --git a/openviking/resource/watch_scheduler.py b/openviking/resource/watch_scheduler.py
index 3e6cbfa85..dd5133ae2 100644
--- a/openviking/resource/watch_scheduler.py
+++ b/openviking/resource/watch_scheduler.py
@@ -294,6 +294,7 @@ class WatchScheduler:
summarize=getattr(task, "summarize", False),
processing_mode=getattr(task, "processing_mode", "semantic_and_vectors"),
watch_interval=task.watch_interval,
+ enforce_public_remote_targets=True,
**processor_kwargs,
)
diff --git a/openviking/resource/watch_storage.py b/openviking/resource/watch_storage.py
index 9ef4b7d13..677048760 100644
--- a/openviking/resource/watch_storage.py
+++ b/openviking/resource/watch_storage.py
@@ -4,6 +4,8 @@
from __future__ import annotations
+from openviking.core.namespace import uri_parts
+
WATCH_TASK_STORAGE_URI = "viking://resources/.watch_tasks.json"
WATCH_TASK_STORAGE_BAK_URI = "viking://resources/.watch_tasks.json.bak"
WATCH_TASK_STORAGE_TMP_URI = "viking://resources/.watch_tasks.json.tmp"
@@ -15,11 +17,14 @@ WATCH_TASK_CONTROL_URIS = frozenset(
WATCH_TASK_STORAGE_TMP_URI,
}
)
+_WATCH_TASK_CONTROL_NAMES = frozenset(uri.rsplit("/", 1)[-1] for uri in WATCH_TASK_CONTROL_URIS)
def is_watch_task_control_uri(uri: str) -> bool:
"""Return True when a URI points at internal watch-task control state."""
if not isinstance(uri, str):
return False
- normalized = uri.rstrip("/")
- return normalized in WATCH_TASK_CONTROL_URIS
+
+ # Match the logical URI segments used by storage, not the caller's spelling.
+ parts = uri_parts(uri)
+ return len(parts) == 2 and parts[0] == "resources" and parts[1] in _WATCH_TASK_CONTROL_NAMES
diff --git a/tests/resource/test_watch_scheduler.py b/tests/resource/test_watch_scheduler.py
index 43e5097d0..627bed3e8 100644
--- a/tests/resource/test_watch_scheduler.py
+++ b/tests/resource/test_watch_scheduler.py
@@ -141,3 +141,4 @@ class TestWatchSchedulerResourceExistence:
assert resource_service.calls
assert resource_service.calls[0]["processing_mode"] == "vectors_only"
+ assert resource_service.calls[0]["enforce_public_remote_targets"] is True
diff --git a/tests/server/test_watch_task_acl.py b/tests/server/test_watch_task_acl.py
index bd5584de3..e42166190 100644
--- a/tests/server/test_watch_task_acl.py
+++ b/tests/server/test_watch_task_acl.py
@@ -119,3 +119,19 @@ def test_content_write_rejects_watch_task_control_files(uri):
with pytest.raises(InvalidArgumentError, match="watch task control file"):
coordinator._validate_target_uri(uri)
+
+
+ "uri",
+ [
+ "viking://resources//.watch_tasks.json",
+ "resources//.watch_tasks.json.bak",
+ "/resources///.watch_tasks.json.tmp/",
+ ],
+)
+def test_redundant_separator_aliases_cannot_bypass_watch_task_acl(bare_viking_fs, user_ctx, uri):
+ assert bare_viking_fs._is_accessible(uri, user_ctx) is False
+
+ coordinator = object.__new__(ContentWriteCoordinator)
+ with pytest.raises(InvalidArgumentError, match="watch task control file"):
+ coordinator._validate_target_uri(uri)