Deno: Digging Tunnels out of a JS Sandbox
Deno's permission sandbox normalised paths without resolving symlinks and checked permissions separately from the actual file access, so a script could bypass read/deny lists and, via a race condition between directory changes and permission checks, gain arbitrary read and write. With arbitrary write the authors overwrote a V8 builtin through /proc/self/mem to run shellcode and obtain code execution.
Both Deno and Node.js are runtimes for JavaScript, TypeScript, and WebAssembly based on V8. Ryan Dahl, the founder of Node.js, announced Deno during his talk at the JsConf EU 2018 with the title 10 Things I Regret About Node.js.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the sandbox normalised paths lexically without resolving symlinks, and performed the permission check and the file access as two separate steps on a working directory that could change in between.
Impact
A script confined to reading and writing only its own directory could read and write arbitrary files and, on Linux/AMD64, achieve code execution; the authors note the technique did not work on Deno Deploy because it uses a virtual file system.
What the attacker needed
Script runs under a read/write sandbox; write access in the working directory; Linux with /proc mounted; Deno 1.39.4 or 1.42.1
The fix
The issues were disclosed to Deno; the text does not state that a specific fix was applied, though it notes the race condition was still present in a later version.
How it was found
- Run Deno with read and write permission limited to the current directory.
- Create a deep chain of nested subdirectories inside the allowed directory.
- Repeatedly switch the working directory between the allowed root and the deep subdirectory.
- Request a relative path with enough parent steps to reach outside the allowed directory, retrying until the check and the read disagree.
- Read the process memory map and open the process memory file for writing the same way.
- Compute the address of a V8 builtin from the map, overwrite its instructions with shellcode, and call it.
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 write-up has not been written yet. The Original tab links to the source.
Deno is a JavaScript runtime that tries to limit what a script can do, for example only reading files in one folder. The checks compared a cleaned-up version of the path but ignored shortcuts called symlinks, and the check happened at a different moment from the actual file open, so a script could trick the runtime into touching files it was never allowed to. Once a script can write anywhere, it can also change the running program's own memory and execute commands.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.