test(cache): pin the remove_cached containment guard against a symlink escape - #135
Merged
Merged
Conversation
…k escape
remove_cached_rejects_path_traversal used a non-hex key ("../../etc"),
which the 64-hex validator (CapsuleKey::parse) refuses BEFORE any path is
built — so the canonicalize + starts_with(cache) containment guard was
never exercised. A valid 64-hex key cannot escape <cache>/modules on its
own, so exercising the guard needs a compromised cache layout: a symlink
inside the cache pointing at a file outside it.
Add remove_cached_containment_guard_refuses_a_symlink_escape (unix): plant
such a symlink and assert a well-formed remove is refused and the outside
file survives. Verified it fails when the guard is deleted (mutation check).
Rename the existing test to remove_cached_rejects_a_non_canonical_key_at_the_validator
so each test names the gate it actually pins.
The sibling concern in #1622 (the availability-batch non-canonical-key test)
is already satisfied: availability_batch_rejects_a_non_canonical_key_without_touching_the_filesystem
now plants a real out-of-cache file and drives .. / ../secret traversals that
collapse onto it, so it is non-vacuous (would answer available:true without
the guard).
Closes #1622
Co-Authored-By: Claude <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.
What changed
Closes #1622.
(a) — the containment guard was untested (fixed).
remove_cached_rejects_path_traversalfed a non-hex key ("../../etc"), which the 64-hex validator (CapsuleKey::parse) refuses before any path is built — so thecanonicalize+starts_with(cache)containment guard incapsule_store.rs(cache_remove_cached) was never exercised. If that guard were deleted, the test still passed.A valid 64-hex key can't contain
.//, so it can never escape<cache>/moduleson its own — the guard is defense-in-depth against a compromised cache layout. The new test exercises it directly:remove_cached_containment_guard_refuses_a_symlink_escape(#[cfg(unix)]): plants a symlink at<cache>/modules/<store>→ a separate out-of-cache tempdir holding<root>.module, then asserts a well-formedcache_remove_cachedis refused ("outside the cache") and the outside file survives.remove_cached_rejects_a_non_canonical_key_at_the_validatorso each test names the gate it actually pins.(b) — already satisfied, no change. #1622's second concern (the availability-batch non-canonical-key test being vacuous) is already resolved in current code:
availability_batch_rejects_a_non_canonical_key_without_touching_the_filesystemnow plants a real out-of-cachesecret.moduleand drives../../secrettraversals that collapse onto it, soavailable == falseis non-vacuous — it would answertruewithout the guard. Documented in the commit body; nothing to change.Verification
cargo fmt --all -- --checkclean ·cargo clippy -p dig-node-core --all-targets --all-features -D warningsclean.Version
test:→ patch bump[workspace.package].version0.72.5 → 0.72.6.Generated by Claude Code