AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(backend/copilot): trust reads of memories, installed skills and owned workspace paths (#14997)
Reinier van der Leer30370449e839
diff --git a/autogpt_platform/backend/backend/copilot/gate/reads.py b/autogpt_platform/backend/backend/copilot/gate/reads.pyindex 5586e3ea7e..0a9506d46b 100644--- a/autogpt_platform/backend/backend/copilot/gate/reads.py+++ b/autogpt_platform/backend/backend/copilot/gate/reads.py@@ -11,6 +11,7 @@ reads what the model would read and the stored bytes are what it would have got.import base64import jsonimport logging+import posixpathimport refrom contextvars import ContextVarfrom datetime import UTC, datetime@@ -22,7 +23,8 @@ from pydantic import BaseModel, ConfigDictfrom backend.api.features.graph_executions.review.model import PendingHumanReviewModelfrom backend.copilot.constants import AUTOPILOT_NAME, COPILOT_NODE_PREFIXfrom backend.copilot.model import ChatSession-from backend.copilot.tools.models import ApprovalRequiredResponse+from backend.copilot.tools.models import ApprovalRequiredResponse, ResponseType+from backend.data.workspace_scope import EXPERTS_ROOT, SKILLS_ROOTfrom . import active_mode, heldfrom . import review as review_store@@ -32,7 +34,9 @@ from .policy import DEFAULT_MODElogger = logging.getLogger(__name__)-# Every tool whose output is bytes AutoPilot did not author (plan A4).+# Every tool whose output is bytes AutoPilot did not author (plan A4). The+# user's own memories are left out: a memory is content they already trust+# (Reinier, 2026-09-28). ``trusted_read`` exempts installed skills.JUDGED_READS: frozenset[str] = frozenset({"bash_exec",@@ -41,8 +45,6 @@ JUDGED_READS: frozenset[str] = frozenset("browser_screenshot","delegate_to_expert","get_sub_session_result",- "memory_forget_search",- "memory_search","read_expert_chat","read_skill","read_workspace_file",@@ -68,6 +70,10 @@ model_view: ContextVar[Callable[[str, bool], str] | None] = ContextVar("held_read_model_view", default=None)+_WORKSPACE_READS = (+ ResponseType.WORKSPACE_FILE_CONTENT,+ ResponseType.WORKSPACE_FILE_METADATA,+)_SOURCE_KEYS = ("url","query",@@ -204,7 +210,7 @@ async def screen_read(``output`` is what the model would receive; ``text`` and ``images`` arewhat of it can be read. Any failure in here withholds the read."""- if tool_name not in JUDGED_READS:+ if tool_name not in JUDGED_READS or trusted_read(tool_name, args, output):return Nonesource = source_of(tool_name, args)try:@@ -240,6 +246,44 @@ async def screen_read(return _stub(tool_name, source, _UNRECORDABLE, session)+def trusted_read(tool_name: str, args: dict[str, Any], output: str) -> bool:+ """Whether the read is of an installed skill, which the user already+ chose to trust, marketplace installs included (Reinier, 2026-09-28)."""+ if tool_name == "read_skill":+ # Any other name reaches outside the skill folders, which a slug cannot.+ from backend.copilot.tools.skills import is_skill_slug++ name = args.get("name")+ return isinstance(name, str) and is_skill_slug(name.strip().lower())+ if tool_name == "read_workspace_file":+ return is_skill_path(_opened_path(output))+ return False+++def is_skill_path(path: str | None) -> bool:+ """A workspace path under an installed-skill folder. Only the skills+ registry writes there; ``write_workspace_file`` refuses these roots."""+ if not path or posixpath.normpath(path) != path:+ return False+ if path.startswith(SKILLS_ROOT):+ return True+ expert, _, rest = path.removeprefix(EXPERTS_ROOT).partition("/")+ return path.startswith(EXPERTS_ROOT) and bool(expert) and rest.startswith("skills/")+++def _opened_path(output: str) -> str | None:+ """The path of the file the reader opened, as its row records it: an+ argument can be relative, or resolve under the session."""+ try:+ data = json.loads(output)+ except ValueError:+ return None+ if not isinstance(data, dict) or data.get("type") not in _WORKSPACE_READS:+ return None+ path = data.get("path")+ return path if isinstance(path, str) else None++def readable_parts(output: str) -> tuple[str, tuple[Image, ...]]:"""The text and images a model can read out of a registry tool's output.diff --git a/autogpt_platform/backend/backend/copilot/gate/reads_test.py b/autogpt_platform/backend/backend/copilot/gate/reads_test.pyindex 284efdd812..9ee19380ad 100644--- a/autogpt_platform/backend/backend/copilot/gate/reads_test.py+++ b/autogpt_platform/backend/backend/copilot/gate/reads_test.py@@ -478,13 +478,16 @@ async def test_a_held_read_is_named_by_its_source_on_the_card_and_the_chain_row(async def test_a_held_read_with_no_named_source_says_what_returned_it(rows):with patch(f"{_READS}.judge_content", _judge(_HELD)):result = await _call(- _Fetch(_MARKER, name="memory_search"), _session(), {"limit": 3}+ _Fetch(_MARKER, name="search_feature_requests"), _session(), {"limit": 3})(row,) = rows.rows.values()- assert row.payload["headline"]["ask"] == "Let Otto read what memory search returned"+ assert (+ row.payload["headline"]["ask"]+ == "Let Otto read what search feature requests returned"+ )stub = json.loads(result.output)- assert stub["ask"] == "Read what memory search returned"+ assert stub["ask"] == "Read what search feature requests returned"assert stub["object"] is None@@ -602,3 +605,99 @@ async def test_an_expired_release_already_delivered_reports_it_was_delivered(rowoutcome, _ = await reads.answered_read("user-1", review)assert outcome == "closed"+++class _OpenedFile(ToolResponseBase):+ type: ResponseType = ResponseType.WORKSPACE_FILE_CONTENT+ path: str+ mime_type: str = "text/markdown"+ content_base64: str = base64.b64encode(_MARKER.encode()).decode()+++class _WorkspaceRead(_Fetch):+ """A workspace read whose row sits at ``opened``, whatever it was asked."""++ def __init__(self, opened: str):+ super().__init__("", name="read_workspace_file")+ self.opened = opened++ async def _execute(self, user_id, session, **kwargs):+ return _OpenedFile(message="file", path=self.opened)+++ "tool, args",+ [+ ("memory_search", {"query": "business goals"}),+ ("memory_forget_search", {"query": "old plan"}),+ ("read_skill", {"name": "Quarterly-Report "}),+ ],+)+async def test_memories_and_installed_skills_are_not_judged(rows, tool, args):+ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge):+ result = await _call(_Fetch(_MARKER, name=tool), _session(), args)+ judge.assert_not_awaited()+ assert result.success and _MARKER in result.output and rows.rows == {}+++async def test_a_skill_name_that_is_not_a_slug_is_judged(rows):+ """``read_skill`` joins the name into a path, so ``..`` leaves the skills."""+ with patch(f"{_READS}.judge_content", _judge(_HELD)):+ result = await _call(+ _Fetch(_MARKER, name="read_skill"), _session(), {"name": "../uploads/x"}+ )+ assert _MARKER not in result.output and len(rows.rows) == 1+++ "opened", ["/skills/report/SKILL.md", "/experts/e1/skills/report/refs/a.md"]+)+async def test_a_workspace_read_of_an_installed_skill_is_not_judged(rows, opened):+ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge):+ result = await _call(_WorkspaceRead(opened), _session(), {"path": opened})+ judge.assert_not_awaited()+ assert result.success and rows.rows == {}+++ "opened",+ [+ "/sessions/session-1/uploads/a.md",+ "/uploads/a.md",+ "/skills/../uploads/a.md",+ "/experts/e1/notes.md",+ "/experts//skills/a.md",+ "/skillset/a.md",+ ],+)+async def test_a_workspace_read_outside_the_skill_folders_is_judged(rows, opened):+ with patch(f"{_READS}.judge_content", _judge(_HELD)):+ result = await _call(_WorkspaceRead(opened), _session(), {"path": opened})+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_a_skill_path_argument_does_not_unlock_the_file_it_opened(rows):+ """Trust follows the row the reader opened, not the path it was asked for."""+ with patch(f"{_READS}.judge_content", _judge(_HELD)):+ result = await _call(+ _WorkspaceRead("/sessions/session-1/skills/x/SKILL.md"),+ _session(),+ {"path": "/skills/x/SKILL.md"},+ )+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_a_skills_copy_in_the_sandbox_is_still_judged(rows):+ """The working-directory copy is writable by the model's own shell."""++ async def read_file(args):+ return {"content": [{"type": "text", "text": _MARKER}], "isError": False}++ session = _session()+ set_execution_context("user-1", session)+ wrapper = _make_truncating_wrapper(read_file, "read_file", required_args=["path"])+ with patch(f"{_READS}.judge_content", _judge(_HELD)):+ result = await wrapper({"path": "/home/user/skills/report/SKILL.md"})+ assert _MARKER not in json.dumps(result) and len(rows.rows) == 1diff --git a/autogpt_platform/backend/backend/copilot/tools/skills.py b/autogpt_platform/backend/backend/copilot/tools/skills.pyindex 9e988dc209..46d22f7776 100644--- a/autogpt_platform/backend/backend/copilot/tools/skills.py+++ b/autogpt_platform/backend/backend/copilot/tools/skills.py@@ -383,6 +383,10 @@ def render_skill_markdown(skill: ParsedSkill) -> str:return f"---\n{frontmatter}\n---\n\n{skill.body.rstrip()}\n"+def is_skill_slug(name: str) -> bool:+ return bool(_NAME_RE.fullmatch(name))++def _validate_name(name: str) -> str | None:if not _NAME_RE.match(name):return (