extract: private cache dir and per-file integrity manifest#74
Merged
Conversation
The extract cache holds the runner binary and its libraries — an executable that will later be spawned as the VM runner subprocess. A world-readable or group-writable cache directory permits a same-host local attacker to read the bundle (minor) or, worse, replace it before the next spawn (local code execution in the invoking user's session). 0o700 keeps the cache contents readable and writable only by the invoking user. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous .version marker only stored the expected aggregate bundle hash; isValid compared the stored string to the recomputed one. It did not re-read the extracted files, so a cached binary or library that had been replaced or silently corrupted after extraction was treated as valid on every subsequent Ensure. Replace the marker with a JSON manifest listing the bundle version, the aggregate hash, and a per-file SHA-256 of every extracted artifact. On Ensure, isValid now walks the manifest and re-hashes each file on disk; any mismatch triggers a re-extract, which removes the stale target dir first since os.Rename cannot replace an existing directory. Tests cover the happy path (Ensure -> isValid), wrong bundle hash, missing manifest, and — the new guarantee — a cached file modified after extraction causes isValid to return false and a follow-up Ensure to re-extract the original content. 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.
Summary
Phase 6 of the hardening series. Two changes to the extract cache
(
extract/bundle.go), which holds the spawned runner binary andits shared libraries.
Cache directory mode 0o700. Previously 0o755. The cache
holds an executable that will later be spawned; world/group
readability exposes the bundle and a writable sibling permits
local code injection. Private-by-default is the correct posture.
Per-file manifest replaces the
.versionmarker. The oldmarker stored only the expected aggregate bundle hash, which
isValidcompared against a recomputed value. It did notre-read the extracted files — a cached binary that had been
silently replaced or corrupted after extraction still looked
valid on every subsequent
Ensure.The new
.manifest.jsonrecords the bundle version, theaggregate hash, and a SHA-256 per extracted artifact.
isValidwalks the manifest and re-hashes each file on disk; any
mismatch triggers a re-extract. Re-extract removes the stale
target dir first because
os.Renamecannot replace an existingdirectory.
Commits are self-contained with tests.
task verifygreen atevery commit.
Test plan
task verifygreen at every commitTestBundle_Ensure_CacheDirIsPrivate— cache dir mode is 0o700.TestBundle_IsValid_TamperedFileTriggersReextract— a filemodified after extraction is detected; a follow-up
Ensurerestores the original content.
.versionfilesdirectly; they now go through
Ensureto produce a validmanifest.
brood-boxlocalreplace: rebuilt bbox,VM boots, SSH + hooks round-trip clean.
🤖 Generated with Claude Code