Skip to content

fix(files): never write through a dangling symlink - #28385

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/cs-dangling-symlink-write
Oct 14, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/cs-dangling-symlink-write

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

ELI5

A file save can be tricked into creating a file outside the folders Orca is allowed to write to. If a project contains a "broken" shortcut (a symbolic link whose target doesn't exist yet) that points outside the project, saving to that shortcut creates the file at the outside location. Orca's permission check approved the shortcut's own location (inside the project) instead of where the save actually lands. Now a save through any broken shortcut is refused.

PR 1 of 6 in the chat-scratch stack. It depends on nothing; PR 2 (rename the chat visuals folder to the chat scratch folder) builds on this branch. The bug already exists on main and the fix stands on its own.

What Changed

Before: saving to repo/escape.txt, where escape.txt is a broken link to /somewhere/outside/new.txt, was allowed and created /somewhere/outside/new.txt. (A broken link to a folder in the middle of the path was also approved, but the write then failed when creating the missing folders, so only the last-segment case created a file outside.)

After: that save (and the folder-link one) is refused with the usual "outside allowed directories" error, and nothing is created outside. Creating new files under missing folders inside an allowed folder (repo/new/nested/file.ts) is unchanged, and links whose targets exist are handled exactly as before.

One behaviour change versus main: a broken link that points somewhere inside the project is now refused too. On main, saving to it created the in-project file it pointed to; now that save shows the same "outside allowed directories" error, and opening such a link shows that error instead of "file not found". Creating the target file first (or saving to the target directly) still works.

Mechanism: resolveAuthorizedPath (src/main/ipc/filesystem-auth.ts) handles a path that doesn't exist yet by walking up to the nearest folder that does exist, resolving that folder's real location, and checking the full path against the allowed folders. A broken link made that walk wrong: resolving its real location fails with "not found" (because its target is missing), so the walk treated the link as a missing name, stepped over it, and approved the link's own path. The write then followed the link out. Now, when a step in the walk fails with "not found" but a link is actually there (so the link is broken), the request is refused. This applies to the last part of the path and to any folder in the middle of it. Every caller of resolveAuthorizedPath gets the fix: the desktop file IPC, the local filesystem provider, and runtime file commands on a paired host.

Why

The approval and the write have to agree on where the bytes go. For a broken link, the operating system is the only thing that knows where a write would land, and it won't say until the write happens. Refusing in the one place that already resolves real locations fixes every write path at once, instead of adding a second check inside each writer.

Alternatives considered:

  • Follow the broken link by hand and approve its target. Keeps the in-project broken-link save working, but re-implements the operating system's path resolution. Review showed it gets relative links reached through a folder link wrong: it can approve a different file than the one the link names, or loop forever and hang the request. Making it correct needs a hop limit and resolution against each link's real folder, a new mechanism for a rare case.
  • Open files with "don't follow links" in each writer. Would need changes in every write, append and create path.

No difference from the common pattern: a path whose real location can't be resolved is not authorized.

Linked Issue

None (found while planning the chat scratch folder work; the bug predates it).

Visual Proof

N/A: no UI change. The only visible difference is that saving to or opening a broken link shows the existing "outside allowed directories" error.

Testing

  • Extended the existing real-filesystem symlink test in src/main/ipc/filesystem-auth.test.ts: a broken link pointing outside and a broken link pointing inside are both refused. Verified it fails on main's code (the outside link was approved) and passes with the fix. The existing "missing nested descendants" test keeps nested creation covered.

  • Ran every test file that imports filesystem-auth plus the provider tests (1,279 passed). Node typecheck clean. Symlink tests skip on Windows like the existing ones (creating links needs elevated rights there); the check uses lstat, which reports Windows symbolic links and junctions as links (not verified on Windows in this PR).

  • macOS only locally. SSH: the relay authorizes paths on its own side and is not changed here; a paired Orca host runs this same function, so it is covered.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: closes a write outside the allowed folders. Cross-platform: no new path handling; the only new call is lstat. Performance: one extra lstat only when a path segment is missing.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

A path that doesn't exist yet was authorized by walking up to the nearest
existing folder. A dangling symlink fails realpath with ENOENT, so the walk
stepped over it and approved the link's own path; the write then followed
the link and created its target outside the allowed folders. The walk now
continues from the link's target, and returns that real destination.
Following a dangling link by hand resolved relative targets against the
lexical parent, not the link's real folder: through a folder link the walk
could loop forever or authorize the wrong file. Refuse instead: realpath
can't say where a dangling link leads, but a write would follow it.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 14, 2026 01:42
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

When resolving a missing path, the code now checks whether its nearest existing ancestor is a dangling symlink. If it is, the resolver denies authorization. Tests cover dangling symlinks that target missing files inside and outside the repository.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to e04ba

Authorized file writes can escape their allowed directory if an ancestor is swapped to a dangling symlink between validation and use. Make the writes symlink-safe before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main security fix: preventing writes through dangling symlinks.
Description check Passed The description is detailed and covers the change, rationale, behavior, testing, security, platform considerations, and checklist. It does not include the required Linked Issue reference, and manual t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75e83f22-a439-4c0e-a548-06f0a0aeaec5
📥 Commits

Reviewing files that changed from the base of the PR and between c5d7628 and e04babd.

📒 Files selected for processing: 2
  • src/main/ipc/filesystem-auth.test.ts
  • src/main/ipc/filesystem-auth.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/ipc/filesystem-auth.ts Resolved
@brennanb2025
brennanb2025 merged commit 9db7b8b into main Oct 14, 2026
75 of 77 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/cs-dangling-symlink-write branch October 14, 2026 02:08
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