Skip to content

🤖 fix: block tilde paths from escaping workspace restrictions#1939

Merged
ethanndickson merged 1 commit intomainfrom
fix-tilde-path-escape
Jan 30, 2026
Merged

🤖 fix: block tilde paths from escaping workspace restrictions#1939
ethanndickson merged 1 commit intomainfrom
fix-tilde-path-escape

Conversation

@ethanndickson
Copy link
Member

Summary

Fixes a security bug where tilde-prefixed paths (e.g., ~/cmux/file.ts) could bypass workspace directory restrictions, allowing agents to read/write files anywhere on the filesystem.

Background

validatePathInCwd() checked paths before tilde expansion. Since Node's path.isAbsolute('~/...') returns false, tilde paths were treated as relative and incorrectly passed validation. The actual file operation then expanded the tilde, accessing files outside the workspace.

Example attack: A workspace at ~/.mux/src/coder/worktree-xyz could read ~/cmux/src/secret.ts by using the tilde path, which would:

  1. Pass validation (resolved as ~/.mux/src/coder/worktree-xyz/~/cmux/src/secret.ts - garbage but under cwd)
  2. Actually read /Users/ethan/cmux/src/secret.ts after tilde expansion

Implementation

Expand tildes in validatePathInCwd() before path resolution so validation sees the actual destination path.

Risks

Low - this is a strictly tighter security check. The only potential breakage would be if any legitimate use case relied on tilde paths to access files outside the workspace, which would be a bug anyway.


Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $1.48

@github-actions github-actions bot added the bug label Jan 27, 2026
@ethanndickson ethanndickson force-pushed the fix-tilde-path-escape branch 3 times, most recently from 0850489 to ac13f13 Compare January 28, 2026 14:52
@ethanndickson ethanndickson added this pull request to the merge queue Jan 29, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
Tilde-prefixed paths (e.g., ~/cmux/file.ts) could bypass workspace
directory restrictions because validatePathInCwd() checked the path
before tilde expansion. Node's path.isAbsolute('~/...') returns false,
so these paths were incorrectly treated as relative and resolved within
cwd, passing validation. The actual file operation then expanded the
tilde, accessing files outside the workspace.

Fix: expand tildes in validatePathInCwd() before path resolution so
validation sees the actual destination path.

Adds tests for tilde path rejection.
@ethanndickson ethanndickson added this pull request to the merge queue Jan 29, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
@ethanndickson ethanndickson added this pull request to the merge queue Jan 30, 2026
Merged via the queue into main with commit b8fcc7e Jan 30, 2026
23 checks passed
@ethanndickson ethanndickson deleted the fix-tilde-path-escape branch January 30, 2026 03:57
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