Summary
A filesystem access control flaw in Wasmtime's WASI implementation allows certain embeddings to bypass configured write restrictions on preopened directories.
When DirPerms::MUTATE is combined with FilePerms::READ only, an attacker can open and truncate files using specific WASI open flags, effectively performing unauthorized writes in sandboxes that were intended to be read-only.
Affected context
This vulnerability appears in Wasmtime deployments that embed wasmtime-wasi and configure preopened directories with DirPerms::MUTATE (or DirPerms::all()) while restricting FilePerms to READ only.
It is specifically triggered when guest WebAssembly modules use wasip2 descriptor.open-at or wasip1 path_open with the TRUNCATE open flag.
Typical affected contexts are custom host applications embedding Wasmtime for sandboxed code execution where the host expects certain directories to be non-writable at the file level despite mutable directory permissions.
Exploit preconditions
- Attack surface: Guest WebAssembly modules running under Wasmtime with wasmtime-wasi enabled.
- Required access: Ability to execute or supply a Wasm module in the affected embedding, with access to a preopened directory configured as DirPerms::MUTATE (or DirPerms::all()) plus FilePerms::READ and without FilePerms::WRITE.
- Trigger point: Calls to wasip2 descriptor.open-at or wasip1 path_open specifying OpenFlags::TRUNCATE, thereby opening a file that should not be writable.
- Why exploitation is possible: The TRUNCATE flag was not coupled with OpenMode::WRITE in the open logic, so the subsequent access control check did not recognize the operation as a write, allowing the open-and-truncate operation to proceed despite missing FilePerms::WRITE.
Why this happens
The underlying issue is a mismatch between the intended access control policy and its enforcement in the WASI filesystem implementation.
In crates/wasi/src/filesystem.rs, the OpenFlags::TRUNCATE clause failed to mark the open request as a write operation (missing open_mode |= OpenMode::WRITE), even though truncation semantically modifies file contents.
Access checks later compared the computed open_mode against the configured FilePerms; because the write bit was not set, the check incorrectly treated truncation as a read-only operation and permitted it.
This aligns with CWE-284: Improper Access Control, where a security mechanism is implemented incompletely and allows operations that should have been restricted under the configured permissions.
Potential impact
- Guest modules may truncate files in directories that were intended to be read-only at the file level.
- Sandboxed code could destroy or corrupt configuration, cache, or data files exposed via preopens.
- Integrity of host-managed data within the Wasm sandbox can be compromised.
- Defense-in-depth assumptions about read-only filesystem exposure to untrusted Wasm code may no longer hold.
General mitigation guidance
Effective mitigation focuses on aligning permissions semantics with actual behavior and minimizing trust in guest code:
- Treat file truncation and similar operations as content-modifying writes in access control logic, ensuring that write-like flags map to corresponding write permissions.
- Prefer conservative permission profiles for preopened directories, granting only the minimum DirPerms and FilePerms necessary for the guest workload.
- Separate read-only and mutable data paths explicitly, and avoid configurations that rely on subtle combinations of directory and file permissions for security.
- Apply defense-in-depth by constraining where sensitive files are mounted into the Wasm environment and by validating permission configurations as part of deployment.
How teams detect issues like this
To detect and monitor similar issues:
- Use static analysis or code search to identify permission checks that do not fully account for all write-like flags (such as TRUNCATE, APPEND, or CREATE).
- During code review, verify that each filesystem flag is consistently mapped to a clear read/write/metadata permission model, and that access checks use this unified representation.
- Implement configuration validation or policy checks that flag suspicious combinations such as DirPerms::MUTATE paired with FilePerms::READ-only semantics for directories exposed to untrusted code.
- Consider runtime logging or auditing of filesystem operations (particularly open with unusual flag combinations) invoked by guest modules to spot unexpected write behavior.

