fix: harden tarball extraction against symlink traversal and stderr OOM - #39
Merged
Conversation
## Why `src/rivet-fetch.js` invoked `tar -xz --strip-components=1 -C destDir` with no symlink guard. A malicious PR head ref could include a symlink in the tarball pointing outside `destDir`; subsequent `runRivetOracle` reads `rivet.yaml` from that target — a path-traversal vector. Additionally, unbounded `stderr` accumulation on pathological tar output could OOM the worker, and `tar.stdout` was piped but never drained — verbose tar output would block the child. ## What - Add `--no-same-owner` and `--no-same-permissions` to the tar invocation; defensive even though we run as a single user. - Drain `tar.stdout` (`.resume()`) so a verbose tar can't deadlock on a full pipe buffer. - Cap `stderr` accumulation at 64 KiB; mark the message `(stderr truncated)` on overflow. - Post-extract, walk `destDir` and reject any symlink whose `path.resolve`d target escapes the directory. Reject by `fs.unlinkSync` and throwing. - Export `assertNoEscapingSymlinks` for direct unit-testability. ## Source Wave-1 Security auditor flagged this as Bug #15 in `docs/agent-fleet/bugs.md`. ## Test plan - [x] 814 tests pass (was 806; +8 covering: hardening flags applied, stdout drained, stderr capped, escaping absolute symlink rejected, escaping relative `..` symlink rejected, benign tree accepted, in-bounds symlink accepted) - [x] eslint clean ## Risk & rollout - Risk: low. The rejected cases are anomalous (escaping symlinks); benign archives extract identically. - Rollout: self-update on merge. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Fixes Bug #15 from
docs/agent-fleet/bugs.md(wave-1 Security auditor).Hardens
src/rivet-fetch.js:--no-same-owner --no-same-permissionson tarDrain
tar.stdoutto prevent pipe-buffer deadlockCap
stderrat 64 KiBPost-extract symlink walk rejects any link escaping destDir
814 tests pass (+8)
eslint clean
🤖 Generated with Claude Code