Skip to content

Path-confinement bypass in file_read/file_write (startswith sibling-dir escape) #1021

Closed

Description

@AmitoVrito

Summary

FileReadTool and FileWriteTool enforce their base_dir sandbox with a raw string prefix check:

resolved = Path(file_path).resolve()
if self._base_dir is not None and not str(resolved).startswith(str(self._base_dir)):
    return ToolResult(..., error="Access denied ...")

str.startswith on the resolved path string is a sibling-directory escape. With base_dir=/home/user/ws, an LLM-supplied path resolving to /home/user/ws-secret/creds (or /home/user/workspace-backup/...) passes the guard because the string "/home/user/ws-secret/creds" starts with "/home/user/ws". FileWriteTool._write_blocking additionally does mkdir(parents=True), so this is arbitrary file creation/overwrite outside the sandbox, not just read.

.resolve() already neutralises plain ../, so the practical exploit is the shared-prefix sibling class.

  • src/synapsekit/agents/tools/file_read.py:57
  • src/synapsekit/agents/tools/file_write.py:72

The path argument is LLM/agent-controlled tool input, so this is reachable by prompt injection or an adversarial task whenever an agent is given these tools with a base_dir.

Severity

HIGH — confinement bypass, LLM-reachable, read and write.

Fix

Use Path.is_relative_to (the pattern already used correctly at mesh/loaders.py:150 and sandbox/apply.py:35) instead of str.startswith. The docstrings claim to "mirror the mesh loader precedent" — this restores that. Non-breaking: legitimate in-tree paths still pass.

Also (defense-in-depth, this scope): file_list.py and pdf_reader.py have no confinement at all — add an optional base_dir using the same is_relative_to guard.

Acceptance

  • Regression test: sibling-prefix path ({base}-secret) is rejected for both read and write; in-tree paths still allowed; .. traversal rejected.
  • CHANGELOG [Unreleased] Security entry.

Activity

  1. added
    bug
    security
    on Sep 8, 2026
  2. added a commit that references this issue on Sep 8, 2026
  3. added a commit that references this issue on Sep 12, 2026
    39bfc19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions