Skip to content

Commit

Permalink
lib,permission: restrict process.binding when pm is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Aug 9, 2023
1 parent ae25da2 commit bd7443a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
ERR_MANIFEST_ASSERT_INTEGRITY,
ERR_NO_CRYPTO,
ERR_MISSING_OPTION,
ERR_ACCESS_DENIED,
} = require('internal/errors').codes;
const assert = require('internal/assert');
const {
Expand Down Expand Up @@ -536,6 +537,9 @@ function initializeClusterIPC() {
function initializePermission() {
const experimentalPermission = getOptionValue('--experimental-permission');
if (experimentalPermission) {
process.binding = function binding(_module) {
throw new ERR_ACCESS_DENIED('process.binding');
};
process.emitWarning('Permission is an experimental feature',
'ExperimentalWarning');
const { has, deny } = require('internal/process/permission');
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/permission/processbinding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const common = require('../../common');
common.skipIfWorker();

const assert = require('assert');

{
assert.throws(() => {
process.binding();
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
}));
}

{
assert.throws(() => {
process.binding('async_wrap');
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
}));
}

{
assert.throws(() => {
process.binding('fs');
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
}));
}
26 changes: 26 additions & 0 deletions test/parallel/test-permission-processbinding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const common = require('../common');
common.skipIfWorker();

if (!common.hasCrypto) {
common.skip('no crypto');
}

const { spawnSync } = require('child_process');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const file = fixtures.path('permission', 'processbinding.js');

// Due to linting rules-utils.js:isBinding check, process.binding() should
// not be called when --experimental-permission is enabled.
// Always spawn a child process
{
const { status, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission', '--allow-fs-read=*', file,
],
);
assert.strictEqual(status, 0, stderr.toString());
}

0 comments on commit bd7443a

Please sign in to comment.