Skip to content

fix(wasi): grant filesystem capability on --wasi-fs + close sandbox-escape hazard (#392) - #396

Merged
avrabe merged 1 commit into
mainfrom
fix/wasi-fs-capability-and-sandbox-escape-392
Jul 8, 2026
Merged

fix(wasi): grant filesystem capability on --wasi-fs + close sandbox-escape hazard (#392)#396
avrabe merged 1 commit into
mainfrom
fix/wasi-fs-capability-and-sandbox-escape-392

Conversation

@avrabe

@avrabe avrabe commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #392. Both parts you flagged, fixed together.

1. The 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 dispatcher.rs's directory_access gate rejected get-directories and 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: 1 that 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.txt escaped the preopen once write is enabled. Replaced all three sites with a lexical is_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-wasi sandbox test: pass
  • kilnd builds (default features)
  • The capability half's end-to-end oracle is your repro (needs the wasm32-wasip2 guest) — I couldn't run that in CI, but the trace-confirmed root cause + the fix are exact.

rivet: SR-33 (v0.4.0). #391 (E03ED witness-core load) landed separately as SR-34.

🤖 Generated with Claude Code

…-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

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

🔍 Build Diagnostics Report

Summary

Metric Base Branch This PR Change
Errors 0 0 0
Warnings 5 5 0

🎯 Impact Analysis

Issues in Files You Modified

  • 0 new errors introduced by your changes
  • 0 new warnings introduced by your changes
  • 0 total errors in modified files
  • 0 total warnings in modified files
  • 0 files you modified

Cascading Issues (Your Changes Breaking Other Files)

  • 0 new errors in unchanged files
  • 0 new warnings in unchanged files
  • 0 unchanged files now affected

Note: "Cascading issues" are errors in files you didn't modify, caused by your changes (e.g., breaking API changes, dependency issues).

✅ No Issues Detected

Perfect! 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

@avrabe
avrabe merged commit 7fbd156 into main Jul 8, 2026
18 checks passed
@avrabe
avrabe deleted the fix/wasi-fs-capability-and-sandbox-escape-392 branch July 8, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kilnd --wasi-fs/--dir is a silent no-op: filesystem capability never enabled, preopens unusable (preview2 guest gets ENOENT on all paths)

1 participant