Skip to content

fix(files): open links out of the task, read-only unless the user granted the target - #469

Merged
simion merged 3 commits into
simion:mainfrom
wagoodman:feature/symlink-escape-bug
Nov 26, 2026
Merged

simion merged 3 commits into
simion:mainfrom
wagoodman:feature/symlink-escape-bug

Conversation

@wagoodman

Copy link
Copy Markdown
Contributor

A worktree's .claude link into the main checkout opened in the editor but failed on save with "path escapes task", and a link to files kept outside the repo could not be opened at all.

I ran into this while looking at dirs within the task that pointed to outside of the task dir:
Screenshot 2026-11-24 at 10 29 10 AM

This isn't necessary to block since I already have sandbox exceptions allowing agents to write to the target dir... so the UI should be able to do the same thing.

Links out of the task now open, read-only by default:

  • reads follow a link out of the task at any depth.
    The buffer is locked, the breadcrumb shows a Read-only badge, and Cmd+S shows a toast saying why
  • a link whose target sits inside a sandbox path the user granted (global defaults, the task's and project's personal lists, the agent's list outside Docker) is writable,
    so the editor can save anything the agent itself can write
  • .termic.yaml grants, built-in runtime paths and regex: entries never count, since a repo or termic authors them, not the user
  • termic's data dir, the keychain dirs, broker spawn dirs, the main checkout and every member repo are refused ahead of any grant.
    .claude is always read-only, even if ~ is granted
  • rename, delete and git operations keep the strict in-task check
  • new task_file_writable IPC tells the editor which files it can save (advisory, the write command checks again)

Also fixes write_atomic, which used a predictable temp name opened with File::create. An agent could plant a link at that name ahead of a save and have termic write the buffer through it. It now uses a random name opened O_EXCL.

Refs #250

A worktree's `.claude` link into the main checkout opened in the editor
but failed on save with "path escapes task", and a link to notes kept
outside the repo could not be opened at all. Reads now follow a link out
of the task at any depth and the file opens read-only: a locked buffer,
a Read-only badge on the breadcrumb, no preview edits, and a toast on
Cmd+S saying why.

- writes stay strict: `task_file_write`, rename, delete and git paths
  keep `safe_task_path`, and the new `task_file_writable` command tells
  the editor which files those are
- a link into termic's data dir, the keychain dirs or the broker's
  per-spawn dirs is still refused; the skills, agents and `mcp.json`
  termic links into `.agents` / `.mcp.json` stay readable
- the read side is a display rule, not a boundary (the webview can
  already read any path), so it is not kept in step with the sandbox
  allowlist
- a read-only buffer uses `EditorState.readOnly` alone, so it still
  takes focus and Cmd+S / Cmd+F reach it
- `task_path_stat`, `task_reveal_path` and `task_file_fp` run off the
  main thread; a missing file under a followed link reads as a dead link
- server tasks still write through links on the box (docs/sandbox.md)

Refs simion#250

Signed-off-by: Alex Goodman <[email protected]>
…ion#250)

A file reached through a link out of the task opened read-only even when
the link landed in a dir the user had allowlisted for the sandbox (e.g.
`~/.local`), so the agent could write a file the editor could not.

`task_file_write` and `task_file_writable` now go through
`safe_task_write_path`: the task as before, or a link's target inside a
sandbox grant from a layer the user owns (global defaults, the task's and
project's personal lists, the task agent's list).

- `.termic.yaml` never counts, since a repo authors it, and neither do the
  built-in runtime paths or `regex:` entries
- the data dir, keychain dirs, broker spawn dirs, the main checkout and
  every member repo are refused ahead of any grant, so granting `~` cannot
  make the `.claude` link write into the repo behind the worktree
- rename, delete and git paths keep the strict check

Refs simion#250

Signed-off-by: Alex Goodman <[email protected]>
The link write rule counted the agent's own `sandbox_allowed_paths` as a
user grant in every realm, but Docker never mounts that list. In a Docker
task the editor could write host paths the container cannot reach (an
agent's config or installed binaries), so an agent could steer a save
there through a link.

- write grants now come from the personal half of `live_sandbox_lists`
  (same layers the spawn reads, `.termic.yaml` dropped), plus the agent
  list only outside Docker
- relative grant entries and ones holding `..` no longer canonicalize
  into something Seatbelt would never match (termic's cwd, every sibling
  task)
- `write_atomic` names its temp file randomly and opens it `O_EXCL`. The
  `{pid}.{seq}` name opened with `File::create` let an agent plant a link
  there ahead of a save and have termic write the buffer through it
- docs and comments now describe the grant exception, and the write rule
  has its own section in docs/sandbox.md

Refs simion#250

Signed-off-by: Alex Goodman <[email protected]>
@simion

simion commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

expand_grants canonicalizes each grant path, but render_profile_with matches Seatbelt's allow rule against the literal substituted path, so a grant that is itself a symlink (e.g. ~/notes -> ~/Dropbox/notes) lets the editor write somewhere the sandboxed agent cannot reach. Worth dropping a grant whose canonical form differs from the substituted one, the same way relative and .. entries are already filtered.

Thanks for the contribution!
— Simion's agent here, he'll take a look at this shortly.

@simion simion left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the read-only link-out behavior, matches the sandbox model well. Merging now.

@simion
simion merged commit 59a7572 into simion:main Nov 26, 2026
3 of 7 checks passed
simion added a commit that referenced this pull request Nov 26, 2026
Both cases #469 added failed on all three platforms. The right panel's
file tree is not inside the task view's [data-task-id], so the scoped
row selectors matched nothing (the tree had every row, "deep" included;
measured with a probe of the DOM). And WebKit's WebDriver returns an
undefined property as null, so the recycled tab's cleared readOnly read
null where the store holds undefined: both mean "not read-only".

Refs #469

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018opNL4DeF5MZjpvmckKSwo
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.

2 participants