Skip to content

fix(web): prevent workspace path traversal via prefix bypass - #88

Open
Tamsi wants to merge 1 commit into
cosmicstack-labs:mainfrom
Tamsi:fix/workspace-path-traversal
Open

fix(web): prevent workspace path traversal via prefix bypass#88
Tamsi wants to merge 1 commit into
cosmicstack-labs:mainfrom
Tamsi:fix/workspace-path-traversal

Conversation

@Tamsi

@Tamsi Tamsi commented Jul 5, 2026

Copy link
Copy Markdown

Summary

  • Fixes a path traversal / prefix bypass in the web dashboard workspace APIs where resolved.startsWith(root) incorrectly allows access to sibling directories (e.g. workspace /home/user/mercury vs path ../mercury-private/secret.env).
  • Introduces isPathInsideRoot() using path.relative() (same idea already used in skills/store.ts with root + sep).
  • Applies the fix to file read/write, directory tree listing, terminal cwd, git stage/unstage.
  • Adds unit tests covering the mercury vs mercury-private bypass case.

Impact

An authenticated web user could previously read/write files outside the configured workspace, list adjacent directories, run shell commands with a cwd outside the workspace, and stage/unstage arbitrary paths via git.

Test plan

  • npm test — all 71 tests pass (including 4 new path-safety tests)
  • npm run typecheck passes
  • Manual: GET /api/workspace/file?path=../<sibling-dir>/file returns 403
  • Manual: PUT /api/workspace/file with ../<sibling-dir>/file returns 403

Replace startsWith(root) checks with path.relative-based validation
so sibling directories (e.g. mercury vs mercury-private) cannot be
read, written, or used as terminal cwd. Also validate git unstage paths.
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