WASI sandbox escape via symlink
The WASI file sandbox, which is meant to restrict file access to explicitly preopened directories, allowed a program to create a symlink inside a preopen that pointed to a host path outside it. An attacker could then open and read that symlink, gaining read (and claimed write) access to arbitrary host files.
Originally disclosed on HackerOne
- Triaged in 4 hours
- Fixed in 9 months
- Disclosed after 22 months
Summary: A WASI + WASM program can use path_symlink to read arbitrary files on the host machine
Description: The experimental, off-by-default WASI interface sandboxes local file I/O via ‘preopens’ paths. I can read files outside of this sandbox by creating a symlink in a preopen to a different location on the local file system.
Steps To Reproduce:
I’m working on a Kotlin/WASM program so I’m going to provide pseudocode:
path_symlink(
old_path = "/etc/passwd"
fd = 3,
new_path = "passwords.txt",
)
val fd = path_open(
fd = 3,
dirflags = 0,
path = "passwords.txt",
oflags = 0,
fs_rights_base = right_fd_read,
fs_rights_inheriting = 0,
fdflags = 0
)
val iovs = allocate(8192)
fd_read(
fd = fd,
iovs = iovs.address,
iovsSize = 1
)
This is based on the Okio WASI integration: https://github.com/square/okio/blob/master/okio-wasifilesystem/src/wasmTest/kotlin/okio/WasiTest.kt
Impact: Can’t run untrusted code via WASI
Impact
Reading and writing an arbitrary file off the host file system. Escaping WASI’s sandbox.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
A WASI program could read and write arbitrary files on the host file system, escaping the sandbox, which means untrusted WASI code cannot be run safely.
What the attacker needed
Ability to run a WASI program; a preopened directory is available
How it was found
- Create a symlink inside a preopened directory whose target is a host path outside the sandbox.
- Open the newly created symlink through the preopen with read rights.
- Read from the returned file descriptor to obtain the contents of the host file.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
WASI is a way to run WebAssembly programs with controlled access to things like files. It is supposed to only let a program touch folders that were deliberately shared with it, called preopens. Here, a program could create a shortcut (a symlink) inside a shared folder that pointed somewhere else on the machine, and then follow that shortcut to read files it should never see.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.