Skip to content

feat: please turn the WASI returnOnExit option to default true #46923

Closed
@HarikrishnanBalagopal

Description

@HarikrishnanBalagopal

Feature Request

Overview

node/doc/api/wasi.md

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`.

node/lib/wasi.js

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.wasiIssues and PRs related to the WebAssembly System Interface.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions