-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Feature Request
Overview
Lines 139 to 142 in c4103c1
| * `returnOnExit` {boolean} By default, WASI applications terminate the Node.js | |
| process via the `__wasi_proc_exit()` function. Setting this option to `true` | |
| causes `wasi.start()` to return the exit code rather than terminate the | |
| process. **Default:** `false`. |
Lines 112 to 116 in c4103c1
| if (options.returnOnExit !== undefined) { | |
| validateBoolean(options.returnOnExit, 'options.returnOnExit'); | |
| if (options.returnOnExit) | |
| wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this); | |
| } |
The current behaviour is for the WASI/WASM module to exit the process when __wasi_proc_exit is called. Not only that, currently it also allows the WASI module to control the exit code.
This seems like a capability that should be explicitly provided to the module rather than something that is on by default. It's unintuitive that a process running in a sandbox would have the ability to crash the entire app without the caller giving it explicit permission to do so.
This is particularly an issue when running 3rd party modules since you rarely have a complete idea on when and where the module might call __wasi_proc_exit and with what exit codes.
Returning instead of exitting when a sandboxed process finishes aligns better with the principles of least privilege and secure by default.
Context
#46254 (comment)
https://github.com/nodejs/node/blob/main/test/wasi/test-return-on-exit.js