mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
Signed-off-by: Paolo Insogna <paolo@cowtech.it> PR-URL: https://github.com/nodejs/node/pull/62762 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Bryan English <bryan@bryanenglish.com>
77 lines
1.7 KiB
JavaScript
77 lines
1.7 KiB
JavaScript
// Flags: --permission --experimental-ffi --allow-fs-read=*
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('node:assert');
|
|
const { test } = require('node:test');
|
|
|
|
common.skipIfFFIMissing();
|
|
|
|
const ffi = require('node:ffi');
|
|
|
|
const dummyLibraryPath = 'ffi-permission-test-library';
|
|
const denied = {
|
|
code: 'ERR_ACCESS_DENIED',
|
|
permission: 'FFI',
|
|
message: /Access to this API has been restricted\. Use --allow-ffi to manage permissions\./,
|
|
};
|
|
|
|
test('process.permission reports ffi denied by default', () => {
|
|
assert.strictEqual(process.permission.has('ffi'), false);
|
|
});
|
|
|
|
test('permission model blocks dynamic library access', () => {
|
|
assert.throws(() => {
|
|
ffi.dlopen(dummyLibraryPath, {});
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
new ffi.DynamicLibrary(dummyLibraryPath);
|
|
}, denied);
|
|
});
|
|
|
|
test('permission model blocks ffi memory and helper APIs', () => {
|
|
assert.throws(() => {
|
|
ffi.toBuffer(1n, 4);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.toArrayBuffer(1n, 4);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.getInt32(1n);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.setInt32(1n, 0, 1);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.exportString('hello', 1n, 8);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.exportString('hello', 1n, 0);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.exportBuffer(Buffer.alloc(0), 1n, 0);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.exportArrayBuffer(new ArrayBuffer(0), 1n, 0);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.exportArrayBufferView(new Uint8Array(0), 1n, 0);
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.getRawPointer(Buffer.alloc(0));
|
|
}, denied);
|
|
|
|
assert.throws(() => {
|
|
ffi.dlclose({ close() {} });
|
|
}, denied);
|
|
});
|