fix: constrain extractFile reads to the unpacked directory#451
Merged
Conversation
readFileWithFd joined the requested filename onto the `<root>.unpacked` directory without checking containment, so a filename containing `..` segments could resolve to a path outside that directory. Route the read through the existing ensureWithin helper (matching readFileSync) so reads are constrained to the unpacked directory and an escaping filename throws. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0155o3ELzXMVngciL3ZsqXgA
MarshallOfSound
approved these changes
Jun 28, 2026
ckerr
approved these changes
Jun 29, 2026
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.
Requested by Samuel Attard · Slack thread
Before
When reading an unpacked file,
extractFile(viareadFileWithFd) joined the requestedfilenameonto<root>.unpackedwithpath.joinand no containment check. Afilenamecontaining..segments could therefore resolve to a path outside the.unpackeddirectory, causing the read to land somewhere it shouldn't.After
Reads are now constrained to the
.unpackeddirectory. Afilenamethat resolves outside it throws instead of reading the out-of-bounds path. This bringsreadFileWithFdin line withreadFileSync, which already routed its unpacked read through the containment check.How
readFileWithFdnow resolves the target through the existingensureWithin(base, filename)helper (wherebase =${filesystem.getRootPath()}.unpacked``), the same helperreadFileSyncalready uses. `ensureWithin` resolves the path with `path.resolve` and throws when the result is neither equal to the base nor under `base + path.sep`. Both unpacked-read call sites now go through this single helper.Added tests in
test/disk-spec.tscovering bothreadFileSyncandreadFileWithFd: each reads a normal file within.unpackedsuccessfully, and each throws when given a..-containing filename that resolves outside the unpacked directory.🤖 Generated with Claude Code
https://claude.ai/code/session_0155o3ELzXMVngciL3ZsqXgA