44
55> Stability: 1 - Experimental
66
7+ <strong class =" critical " >The ` node:wasi ` module does not currently provide the
8+ comprehensive file system security properties provided by some WASI runtimes.
9+ Full support for secure file system sandboxing may or may not be implemented in
10+ future. In the mean time, do not rely on it to run untrusted code. </strong >
11+
712<!-- source_link=lib/wasi.js -->
813
914The WASI API provides an implementation of the [ WebAssembly System Interface] [ ]
10- specification. WASI gives sandboxed WebAssembly applications access to the
11- underlying operating system via a collection of POSIX-like functions.
15+ specification. WASI gives WebAssembly applications access to the underlying
16+ operating system via a collection of POSIX-like functions.
1217
1318``` mjs
1419import { readFile } from ' node:fs/promises' ;
@@ -20,7 +25,7 @@ const wasi = new WASI({
2025 args: argv,
2126 env,
2227 preopens: {
23- ' /sandbox ' : ' /some/real/path/that/wasm/can/access' ,
28+ ' /local ' : ' /some/real/path/that/wasm/can/access' ,
2429 },
2530});
2631
@@ -44,7 +49,7 @@ const wasi = new WASI({
4449 args: argv,
4550 env,
4651 preopens: {
47- ' /sandbox ' : ' /some/real/path/that/wasm/can/access' ,
52+ ' /local ' : ' /some/real/path/that/wasm/can/access' ,
4853 },
4954});
5055
@@ -97,6 +102,28 @@ Use [wabt](https://github.com/WebAssembly/wabt) to compile `.wat` to `.wasm`
97102wat2wasm demo.wat
98103```
99104
105+ ## Security
106+
107+ <!-- YAML
108+ added: REPLACEME
109+ changes:
110+ - version: REPLACEME
111+ pr-url: https:// github.com/nodejs/node/pull/50396
112+ description: Clarify WASI security properties.
113+ -->
114+
115+ WASI provides a capabilities-based model through which applications are provided
116+ their own custom `env`, `preopens`, `stdin`, `stdout`, `stderr`, and `exit`
117+ capabilities.
118+
119+ **The current Node.js threat model does not provide secure sandboxing as is
120+ present in some WASI runtimes.**
121+
122+ While the capability features are supported, they do not form a security model
123+ in Node.js. For example, the file system sandboxing can be escaped with various
124+ techniques. The project is exploring whether these security guarantees could be
125+ added in future.
126+
100127## Class: `WASI`
101128
102129<!-- YAML
@@ -107,9 +134,7 @@ added:
107134
108135The `WASI` class provides the WASI system call API and additional convenience
109136methods for working with WASI-based applications. Each `WASI` instance
110- represents a distinct sandbox environment. For security purposes, each `WASI`
111- instance must have its command-line arguments, environment variables, and
112- sandbox directory structure configured explicitly.
137+ represents a distinct environment.
113138
114139### `new WASI([options])`
115140
@@ -136,9 +161,9 @@ changes:
136161 * ` env` {Object } An object similar to ` process.env` that the WebAssembly
137162 application will see as its environment. ** Default: ** ` {}` .
138163 * ` preopens` {Object } This object represents the WebAssembly application' s
139- sandbox directory structure. The string keys of `preopens` are treated as
140- directories within the sandbox . The corresponding values in `preopens` are
141- the real paths to those directories on the host machine.
164+ local directory structure. The string keys of `preopens` are treated as
165+ directories within the file system . The corresponding values in `preopens`
166+ are the real paths to those directories on the host machine.
142167 * `returnOnExit` {boolean} By default, when WASI applications call
143168 `__wasi_proc_exit()` `wasi.start()` will return with the exit code
144169 specified rather than terminating the process. Setting this option to
0 commit comments