Skip to content

fix(permissions): close write-path TOCTOU and warn on overbroad roots - #433

Open
HaoChiBao wants to merge 2 commits into
andrewyng:mainfrom
HaoChiBao:fix/35-file-write-toctou
Open

fix(permissions): close write-path TOCTOU and warn on overbroad roots#433
HaoChiBao wants to merge 2 commits into
andrewyng:mainfrom
HaoChiBao:fix/35-file-write-toctou

Conversation

@HaoChiBao

@HaoChiBao HaoChiBao commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #35: two edge cases in file-write path scoping.

  1. Stale path check — today we check that a write path is inside a writable folder when deciding allow/ask, but the real write happens later (after the user approves, or after other tools in the same turn). If a directory in that path is swapped for a symlink that points outside the workspace in between, the earlier check no longer matches reality.
  2. Over-broad folder grant — if someone adds a folder that is (or resolves to) their home directory or something above it, we currently accept that quietly even though it effectively means “write anywhere under home.”

Files changed

File Why
coworker/permissions.py Adds revalidate_write() — same writable-root check as evaluate, meant to run again right before the write.
coworker/engine.py Calls that check in _execute_sync immediately before the tool runs (after approval / auto-allow).
coworker/roots.py Adds overbroad_root_warning() to detect grants that resolve to $HOME or above.
coworker/server/manager.py Uses that helper in add_root: still grants access, but logs and returns a warning.
tests/test_path_scoping.py Covers symlink escape, a symlink swap after the first check, and the over-broad root warning.

Test plan

  • pytest tests/test_path_scoping.py tests/test_tools_permissions.py tests/test_multiroot.py
  • Normal project-root write still works
  • Adding $HOME (or a symlink to it) still grants access and includes a warning

Closes #35

Re-validate writable-root scoping immediately before writes execute, and surface a warning when a granted root resolves to $HOME or above.
Drop patch-path parsing and trim overbroad-root warning/tests to the TOCTOU recheck and $HOME-breadth warn.
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.

[Security] File-write path scoping: TOCTOU + broad-symlink-root edge cases

1 participant