Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ added: v26.9.0
When using the [Permission Model][], a [virtual file system][] cannot be
mounted by default: [`vfs.mount()`][] throws `ERR_INVALID_STATE` unless the
user explicitly passes the `--allow-fs-vfs` flag when starting Node.js.
In audit mode ([`--permission-audit`](#--permission-audit)), mounting is not
refused and no message is published to the diagnostics channel.

A mounted VFS serves paths that the file system permissions do not describe,
so mounting one is gated on its own flag rather than on `--allow-fs-read` or
Expand Down
2 changes: 2 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ process.permission.has('fs.read', 'custom-require-2.js'); // true
When using the Permission Model, a virtual file system cannot be
mounted by default: \fBvfs.mount()\fR throws \fBERR_INVALID_STATE\fR unless the
user explicitly passes the \fB--allow-fs-vfs\fR flag when starting Node.js.
In audit mode (\fB--permission-audit\fR), mounting is not
refused and no message is published to the diagnostics channel.
A mounted VFS serves paths that the file system permissions do not describe,
so mounting one is gated on its own flag rather than on \fB--allow-fs-read\fR or
\fB--allow-fs-write\fR.
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/vfs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ let normalizedVfsRoot = null;
let normalizedVfsRootPrefix = null;

function registerVFS(vfs) {
if (permission.isEnabled() && !getOptionValue('--allow-fs-vfs')) {
// TODO(rafaelgss): publish a diagnostics channel message in audit mode.
if (permission.isEnabled() && !permission.isAuditMode() &&
!getOptionValue('--allow-fs-vfs')) {
throw new ERR_INVALID_STATE(
'VFS cannot be used when the permission model is enabled. ' +
'Use --allow-fs-vfs to allow it.',
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-permission-allow-fs-vfs-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ spawnSyncAndExit(
},
);

// Mounting a VFS is refused under --permission without --allow-fs-vfs, but
// audit mode only observes and lets the mount through.
const mount = `
require('node:vfs').create().mount();
console.log('mounted');
`;

spawnSyncAndExit(
process.execPath,
['--experimental-vfs', '--permission', '-e', mount],
{
status: 1,
signal: null,
stderr: /ERR_INVALID_STATE/,
},
);

spawnSyncAndAssert(
process.execPath,
['--experimental-vfs', '--permission-audit', '-e', mount],
{
stdout: /^mounted$/m,
},
);

if (process.config.variables.node_without_node_options) {
common.skip('missing NODE_OPTIONS support');
}
Expand Down
Loading