"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(memory): validate persistent memory types (#257)
Hinotobi27c74932b162
diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.pyindex e50eef077..736d5aa1d 100644--- a/agent/src/memory/persistent.py+++ b/agent/src/memory/persistent.py@@ -288,6 +288,10 @@ class PersistentMemory:if not stripped_name:raise ValueError("memory name must not be empty or whitespace-only")+ if memory_type not in MEMORY_TYPES:+ allowed = ", ".join(MEMORY_TYPES)+ raise ValueError(f"memory_type must be one of: {allowed}")+# Preserve non-Latin script characters in the slug — collapsing# them all to ``_`` caused two same-length non-Latin names to share a# filename and silently overwrite each other (PR #95 + #104).diff --git a/agent/src/tools/remember_tool.py b/agent/src/tools/remember_tool.pyindex 0fe903772..3b6a3f7a2 100644--- a/agent/src/tools/remember_tool.py+++ b/agent/src/tools/remember_tool.py@@ -86,7 +86,10 @@ class RememberTool(BaseTool):if not title or not content:return json.dumps({"status": "error", "error": "title and content required"})memory_type = kwargs.get("memory_type", "project")- path = self._memory.add(title, content, memory_type, description=title)+ try:+ path = self._memory.add(title, content, memory_type, description=title)+ except ValueError as exc:+ return json.dumps({"status": "error", "error": str(exc)})return json.dumps({"status": "ok", "message": f"Saved: {title}", "path": str(path)})def _recall(self, kwargs: dict) -> str:diff --git a/agent/tests/test_remember_tool_security.py b/agent/tests/test_remember_tool_security.pynew file mode 100644index 000000000..d967f4cdb--- /dev/null+++ b/agent/tests/test_remember_tool_security.py@@ -0,0 +1,40 @@+"""Security regressions for RememberTool persistent memory writes."""++from __future__ import annotations++import json+from pathlib import Path++from src.memory.persistent import PersistentMemory+from src.tools.remember_tool import RememberTool+++def test_remember_rejects_memory_type_path_traversal(tmp_path: Path) -> None:+ """memory_type must not be able to escape the memory directory."""+ memory_dir = tmp_path / "memory"+ outside_dir = tmp_path / "outside"+ outside_dir.mkdir()+ tool = RememberTool(PersistentMemory(memory_dir=memory_dir))++ result = json.loads(tool.execute(+ action="save",+ title="Traversal Proof",+ content="SAFE_MARKER",+ memory_type="../outside/proof",+ ))++ assert result["status"] == "error"+ assert "memory_type" in result["error"]+ assert not (outside_dir / "proof_traversal_proof.md").exists()+++def test_persistent_memory_rejects_unknown_memory_type(tmp_path: Path) -> None:+ """The storage layer enforces the documented memory type enum itself."""+ memory = PersistentMemory(memory_dir=tmp_path / "memory")++ try:+ memory.add("bad type", "content", "../../outside/proof")+ except ValueError as exc:+ assert "memory_type" in str(exc)+ else: # pragma: no cover - makes the assertion message clearer on vulnerable code+ raise AssertionError("PersistentMemory.add() accepted an invalid memory_type")