fix(wasi): grant filesystem capability on --wasi-fs + close sandbox-escape hazard (#392) - #396
Merged
Merged
Conversation
…-escape hazard (#392) Two-part fix for the maintainer-reported #392 (differential oracle: wasmtime grants the same --dir correctly): 1. Silent no-op — kilnd registered a preopen for --wasi-fs/--dir but never enabled the filesystem capability (WasiCapabilities::minimal() leaves read/write/directory/metadata_access = false), so the capability gate rejected every op and the guest got ENOENT on all paths. Now, when fs paths are granted, enable read+write+directory+metadata access (matches wasmtime --dir). kilnd/src/lib.rs. 2. Sandbox escape (the latent hazard the report flagged, exposed once write is enabled) — the descriptor open-at/create/remove checks gated containment on `canonicalize().is_ok()`, which fails for a not-yet-created target, so a write to `../evil.txt` escaped the preopen. Replaced all three sites with a lexical `is_within_sandbox` (rejects any `..` component and absolute-path replacement, independent of existence). Unit-tested: a `..` write to a missing target is rejected (verifies SR-33). kiln-wasi 1 new test passes; kilnd builds. The capability half's end-to-end oracle is the #392 repro (needs a wasm32-wasip2 guest), documented on the issue. Trace: SR-33
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🔍 Build Diagnostics ReportSummary
🎯 Impact AnalysisIssues in Files You Modified
Cascading Issues (Your Changes Breaking Other Files)
✅ No Issues DetectedPerfect! Your changes don't introduce any new errors or warnings, and don't break any existing code. 📊 Full diagnostic data available in workflow artifacts 🔧 To reproduce locally: # Install cargo-kiln
cargo install --path cargo-kiln
# Analyze your changes
cargo-kiln build --output json --filter-severity error
cargo-kiln check --output json --filter-severity warning |
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.
Closes #392. Both parts you flagged, fixed together.
1. The silent no-op
kilnd registered a preopen for
--wasi-fs/--dirbut never enabled the filesystem capability —WasiCapabilities::minimal()leavesread/write/directory/metadata_access = false, sodispatcher.rs'sdirectory_accessgate rejectedget-directoriesand the guest got ENOENT on every path. Now, when fs paths are granted, kilnd enables read+write+directory+metadata access (matching wasmtime's--dir). No more✓ Filesystem paths: 1that grants nothing.2. The sandbox-escape hazard (fixed at the same time, as you recommended)
The open-at/create/remove containment checks gated on
canonicalize().is_ok(), which fails for a not-yet-created target — so a write to../evil.txtescaped the preopen once write is enabled. Replaced all three sites with a lexicalis_within_sandbox()that rejects any..component and absolute-path replacement independent of existence.Unit-tested (
verifies SR-33): a..write to a missing target is now rejected; absolute paths rejected; within-sandbox paths accepted.Verification
kiln-wasisandbox test: passkilndbuilds (default features)rivet: SR-33 (v0.4.0). #391 (E03ED witness-core load) landed separately as SR-34.
🤖 Generated with Claude Code