Skip to content

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

fix(resources): skip unsafe repository paths during upload (#5953)

chenxiaobin-monkey7b7654e80828
diff --git a/openviking/parse/parsers/upload_utils.py b/openviking/parse/parsers/upload_utils.py
index c2ff438b4..8acac98b6 100644
--- a/openviking/parse/parsers/upload_utils.py
+++ b/openviking/parse/parsers/upload_utils.py
@@ -22,6 +22,7 @@ from openviking.parse.parsers.constants import (
)
from openviking.parse.parsers.text_encoding import normalize_text_bytes
from openviking.utils.content_hash import content_md5
+from openviking.utils.path_safety import sanitize_relative_viking_path
from openviking_cli.utils.logger import get_logger
logger = get_logger(__name__)
@@ -218,6 +219,11 @@ async def upload_directory(
# Artifact-relative path under the resource root; the store resolves it
# to a local/agfs location.
target = f"{base}/{rel_path_str}" if base else rel_path_str
+ try:
+ target = sanitize_relative_viking_path(target)
+ except ValueError as exc:
+ logger.warning(f"Skipping {file_path}: {exc}")
+ continue
files_to_upload.append((file_path, target))
if "/" in target:
parent_dirs.add(target.rsplit("/", 1)[0])
diff --git a/tests/test_upload_utils.py b/tests/test_upload_utils.py
index 373ac8403..fa140c6e5 100644
--- a/tests/test_upload_utils.py
+++ b/tests/test_upload_utils.py
@@ -404,6 +404,21 @@ class TestSanitizeRelPath:
class TestUploadDirectoryEdgeCases:
+ @pytest.mark.asyncio
+ async def test_unsafe_path_is_skipped_without_warning_result(self, tmp_path: Path) -> None:
+ (tmp_path / "ok.py").write_text("print(1)", encoding="utf-8")
+ (tmp_path / "%2F.txt").write_text("fixture", encoding="utf-8")
+ store = _RecordingStore()
+
+ count, warnings = await upload_directory(
+ tmp_path, "repository", store=store, artifact_ref=object()
+ )
+
+ assert count == 1
+ assert warnings == []
+ assert "repository/ok.py" in store.writes
+ assert all("%2F.txt" not in path for path in store.writes)
+
@pytest.mark.asyncio
async def test_writes_content_md5_manifest(self, tmp_dir: Path) -> None:
import hashlib