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
8 changes: 8 additions & 0 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ does not exist, the wildcard will not be added, and access will be limited to
yet, make sure to explicitly include the wildcard:
`/my-path/folder-do-not-exist/*`.

Some `node:fs` operations act on an already-open file descriptor rather than a
path, so they cannot be tied to a `--allow-fs-read` or `--allow-fs-write` grant.
When the permission model is enabled these operations are disabled and throw
`ERR_ACCESS_DENIED`, regardless of how the descriptor was obtained. This applies
both to the top-level `node:fs` functions and to the equivalent
`FileHandle` methods, and currently includes `fsync`/`fdatasync`,
`fchmod`, and `fchown` (and their synchronous variants).

#### Configuration file support

In addition to passing permission flags on the command line, they can also be
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,9 @@ async function rmdir(path, options) {
}

async function fdatasync(handle) {
if (permission.isEnabled()) {
throw new ERR_ACCESS_DENIED('fdatasync API is disabled when Permission Model is enabled.');
}
return await PromisePrototypeThen(
binding.fdatasync(handle.fd, kUsePromises),
undefined,
Expand All @@ -1579,6 +1582,9 @@ async function fdatasync(handle) {
}

async function fsync(handle) {
if (permission.isEnabled()) {
throw new ERR_ACCESS_DENIED('fsync API is disabled when Permission Model is enabled.');
}
return await PromisePrototypeThen(
binding.fsync(handle.fd, kUsePromises),
undefined,
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-permission-fs-filehandle-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Flags: --permission --allow-fs-read=*
'use strict';

const common = require('../common');
const { isMainThread } = require('worker_threads');

if (!isMainThread) {
common.skip('This test only works on a main thread');
}

const assert = require('assert');
const { open } = require('fs/promises');
const fixtures = require('../common/fixtures');

const regularFile = fixtures.path('permission', 'deny', 'regular-file.md');

// FileHandle sync operations must be blocked when the permission model is
// enabled, consistent with fs.fsync() / fs.fsyncSync() and fdatasync variants.
(async () => {
const fh = await open(regularFile, 'r');
try {
await assert.rejects(
fh.sync(),
common.expectsError({ code: 'ERR_ACCESS_DENIED' }),
);
await assert.rejects(
fh.datasync(),
common.expectsError({ code: 'ERR_ACCESS_DENIED' }),
);
} finally {
await fh.close();
}
})().then(common.mustCall());
Loading