Skip to content

fix(code): a caller trusted with code/shell may code/read any file her OS user can read - #4829

Merged
joelteply merged 2 commits into
canaryfrom
fix/read-scope-follows-shell-trust
Oct 6, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/read-scope-follows-shell-trust

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Why: code/read refused Kimi a diff she had just written outside her workspace (Path … escapes workspace), while code/shell, which her trust allows, let her cat it. For a caller who can run arbitrary commands, the read sandbox contains nothing and only costs her turns. Joel, 2026-10-06: give the AIs more power, and pull back only on a real problem.

What changes:

  • PathSecurity::validate_read_in(path, ReadScope). Under Host, it also resolves an existing absolute path outside every root. Sandbox is exactly today's validate_read. Relative paths and traversal are judged by the sandbox under both.
  • code/read asks the gate's own resolvers for its scope: is_command_authorized("code/shell", caller_trust(caller)). So the read scope can never be wider than the shell grant, and a provisional remote peer keeps the workspace sandbox exactly as now.
  • Writes never widen. validate_write is unchanged.

Tests: host_scope_reads_outside_the_sandbox_and_only_absolute_paths. Four existing tests in this area fail on Windows on plain canary too, so they aren't this PR's:

  • glob_scoped_to_subdirectory_via_root_param
  • glob_matches_files_by_extension_recursively
  • a_mistyped_path_gets_pointed_at_the_real_one
  • absolute_paths_rebase_inside_refuse_outside_keep_the_slash_idiom

I ran them on canary with no change to confirm. They look like /-vs-\ and Unix-absolute-path assumptions.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

…r OS user can read

Kimi, 2026-10-06: code/read refused a diff she had just written outside her workspace
("Path ... escapes workspace") while code/shell, which her trust admits, let her cat it.
For a caller who may run arbitrary commands, the read sandbox contains nothing and only
costs turns; Joel, the same day: give the AIs more power, pull back only on a real problem.

- PathSecurity::validate_read_in(path, ReadScope): Host also resolves an existing
  ABSOLUTE path outside every root; Sandbox is exactly validate_read. Relative paths and
  traversal are judged by the sandbox under both scopes.
- code/read's scope is asked through the gate's own resolvers:
  is_command_authorized("code/shell", caller_trust(caller)). It can never be wider than
  the shell grant, so a provisional remote peer keeps the workspace sandbox.
- Writes never widen: validate_write is unchanged.

Test: host_scope_reads_outside_the_sandbox_and_only_absolute_paths. Four tests in this
area (three file_engine globs and path recovery, plus path_security's absolute-path
rebase) fail on Windows on canary too, before this change; they are not this PR's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply

Copy link
Copy Markdown
Contributor Author

One small change at d8951ef; the substance is right.

The change: in code_commands.rs, read_scope_of and its doc block were inserted between caller_id's doc comment and caller_id itself. /// binds to the next item, so caller_id loses its docs ("the gated caller identity (an airc peer_id), never a params field … nothing trusts caller-supplied identity") and read_scope_of's rendered doc now opens with them. Move read_scope_of above that doc block, so each function keeps its own.

What's right:

  • The read scope comes from the gate's own resolvers (caller_trust → is_command_authorized("code/shell", …)), so it can never be wider than the shell grant. A provisional remote peer keeps the sandbox exactly as now.
  • Host adds only EXISTING ABSOLUTE paths. A relative path or traversal is judged by the sandbox in both scopes, and writes never widen. The test pins all three.
  • It is the right call by Joel's 10-06 rule. For a caller who can run cat, the read sandbox contained nothing and only cost her turns.

6/6 checks green. I'll approve the head that moves the function.

@joelteply
joelteply enabled auto-merge (squash) October 6, 2026 18:08
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVED at fd6ad5a.

The delta since d8951ef (6/6 green) is the doc move alone: caller_id and read_scope_of each carry their own /// block again, with no code change. The substance is as reviewed: read scope from the gate's own code/shell grant, existing absolute paths only, writes never widen.

@joelteply
joelteply merged commit 3e1a3ce into canary Oct 6, 2026
7 checks passed
@joelteply
joelteply deleted the fix/read-scope-follows-shell-trust branch October 6, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant