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
1 change: 1 addition & 0 deletions lib/ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function DynamicLibrary(path) {
// Let the native constructor produce its usual error.
return FunctionPrototypeCall(NativeDynamicLibrary, this, path);
}
checkFFIPermission();
const readVirtualLibrary = getVfsLibraryReader();
const binary =
readVirtualLibrary === null || typeof path !== 'string' ?
Expand Down
5 changes: 3 additions & 2 deletions src/node_ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,9 @@ void DynamicLibrary::New(const FunctionCallbackInfo<Value>& args) {
// that lives somewhere the dynamic loader cannot open by path (a virtual
// file system). Materialize them into a private, self-cleaning image - the
// same mechanism process.dlopen() uses for such native addons - and load
// that, while still reporting the library's own path in `library.path` and
// any error.
// that. `library.path` and errors from materializing the image report the
// library's own path; a dlopen failure reports the image's path, as given
// by the dynamic loader.
binding::AddonImage image;
if (args.Length() > 1 && !args[1]->IsUndefined()) {
if (!args[1]->IsArrayBufferView()) {
Expand Down
6 changes: 5 additions & 1 deletion test/ffi/test-ffi-permissions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --permission --allow-fs-read=*
// Flags: --permission --allow-fs-read=* --allow-fs-vfs
'use strict';
const common = require('../common');
const assert = require('node:assert');
Expand Down Expand Up @@ -27,6 +27,10 @@ test('permission model blocks dynamic library access', () => {
assert.throws(() => {
new ffi.DynamicLibrary(dummyLibraryPath);
}, denied);
const vfsLibraryPath = `${require('node:vfs').create().mount()}/missing.so`;
assert.throws(() => {
new ffi.DynamicLibrary(vfsLibraryPath);
}, denied);
});

test('permission model blocks ffi memory and helper APIs', () => {
Expand Down
Loading