Skip to content

mcp: sandbox get_agent_file to allowed editor roots#1449

Open
Evanfeenstra wants to merge 1 commit into
mainfrom
mcp/sandbox-get-agent-file
Open

mcp: sandbox get_agent_file to allowed editor roots#1449
Evanfeenstra wants to merge 1 commit into
mainfrom
mcp/sandbox-get-agent-file

Conversation

@Evanfeenstra

Copy link
Copy Markdown
Collaborator

Problem

get_agent_file (GET /repo/agent/file) served any absolute path via res.sendFile with no containment check — an arbitrary file read (e.g. ?path=/etc/passwd, secrets, etc.). The route also has no auth middleware.

Fix

Route the requested path through the existing sandbox primitive resolveInCwd against editorRoots — the same roots the editor tool is already confined to:

  • /tmp (cloned repos live at /tmp/owner/repo)
  • os.tmpdir() (scratch)
  • AGENT_ARTIFACTS_DIR (durable artifacts, when set)

Paths that escape those roots (absolute escapes / ../ traversal) now return 403. editorRoots was made exported to reuse it.

Notes

  • Reuses resolveInCwd (already covered by textEdit.test.ts).
  • This route still has no auth/token check unlike some sibling routes — worth considering separately if externally reachable.

npx tsc --noEmit passes.

get_agent_file served any absolute path via res.sendFile with no
containment check, allowing arbitrary file reads. Route the path through
resolveInCwd against editorRoots (/tmp cloned repos, OS scratch dir, and
AGENT_ARTIFACTS_DIR), returning 403 for paths that escape those roots.
@Evanfeenstra Evanfeenstra requested a review from fayekelmith as a code owner July 9, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant