fix(app-server): sandbox fs/* RPCs to authorized workspace roots#179
Open
andrei-hasna wants to merge 1 commit into
Open
fix(app-server): sandbox fs/* RPCs to authorized workspace roots#179andrei-hasna wants to merge 1 commit into
andrei-hasna wants to merge 1 commit into
Conversation
app-server fs/* methods (readFile, writeFile, createDirectory, getMetadata, readDirectory, remove, copy, watch) accepted arbitrary absolute host paths and forwarded them with sandbox=None, letting a generic initialized client read, write, copy, watch, or recursively delete any host file the app-server process could reach (CWE-862, CWE-22, CWE-284). fs/remove additionally defaulted to recursive+force=true. Add a server-side FsScope guard derived from server-held session state (the active cwd plus effective workspace roots) and authorize every fs/* target against it before touching the filesystem. Targets are fully canonicalized so symlink escapes and absolute-path traversal are rejected; not-yet-existing write/mkdir/copy-destination targets resolve their deepest existing ancestor so a symlinked ancestor cannot escape either. Scope is default-deny when no root is established. fs/remove no longer defaults to recursive/force; both must be requested explicitly, so a client cannot recursively delete even inside scope without opting in (and never outside an authorized root). Add app-server v2 regression tests for out-of-scope denial across all methods, authorized in-scope reads/writes, symlink-escape denial, and the new non-destructive remove defaults, plus fs_scope unit tests. Update the app-server README and fs protocol docs to state the trust/authorization/scope semantics and regenerate schema fixtures. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Risk
app-server
fs/*RPCs (fs/readFile,fs/writeFile,fs/createDirectory,fs/getMetadata,fs/readDirectory,fs/remove,fs/copy,fs/watch) accepted arbitrary absolute host paths and forwarded them to the filesystem withsandbox = None. Any generic initialized app-server client (compromised desktop/UI/plugin/remote-control client or another transport peer) could read, write, copy, watch, or recursively delete arbitrary host files from the app-server process context, bypassing session permission profiles, workspace roots, approval flow, and platform sandboxing.fs/removeadditionally defaulted torecursive+force=true. Classifications: CWE-862 (Missing Authorization), CWE-22 (Path Traversal), CWE-284 (Improper Access Control). Severity P1.Fingerprint:
open-codewith/security/app-server/fs-host-filesystem-unsandboxed-rpc/19dc867ccbd61d8f79b94eeea7b94245587a7e2eb8cedd8051dc688f0442e613Fix
app-server/src/fs_scope.rs(FsScope) derived from server-held session state — the activecwdplus effective workspace roots — never from a client-supplied root. Default-deny when no root is established.fs/*target is authorized before any filesystem access. Targets are fully canonicalized (all symlinks resolved) and checked component-wise against the authorized roots, so symlink escapes, absolute-path traversal, and prefix confusion (/rootvs/root-evil) are rejected. Not-yet-existing write/mkdir/copy-destination targets resolve their deepest existing ancestor, so a symlinked ancestor cannot escape either.fs/copychecks both source and destination;fs/watchchecks the watch path (emittedchangedPathsare always in-scope descendants).fs/removeno longer defaults torecursive/force; both must be requested explicitly, so a client cannot recursively delete even inside scope without opting in, and never outside an authorized root.Validation
Run in
codex-rs/:just test-fast -p codex-app-server --test all fs→ 20 passed (incl. new denial, authorized-scope, symlink-escape, and non-destructive-remove-default tests)cargo test -p codex-app-server --lib fs_scope→ 6 passed (containment, missing-target, sibling-prefix, symlink-escape, empty-deny)just test-fast -p codex-app-server-protocol→ 256 passed (incl. schema fixture drift checks)just check-fast -p codex-app-server→ clean (clippy)just fmt→ cleanIndependent adversarial review found no exploitable bypass; the guard is fail-closed.
Residual risks
Config(cwd + workspace roots), not rebuilt per active thread/session. Still within the authorized roots, but if the startup cwd is broad (repo root/home)fs/*stays authorized across that tree. Follow-up hardening could pin scope per active thread.openat/O_NOFOLLOWin the fs layer.remove/getMetadataon an in-scope symlink whose target is out-of-scope are denied (the link is resolved). Edge case, deny-safe.Commit:
0c716ba66f94c4957d75fb386fc20019ce3b74c1🤖 Generated with Claude Code