GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — process: disallow adding options to process.allowedNodeEnvironmentFlags by aduh95 · Pull Request #36660 · nodejs/node

process: disallow adding options to process.allowedNodeEnvironmentFlags #36660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aduh95 wants to merge 3 commits into nodejs:master from aduh95:process-allowedEnvFlags

Uh oh!

There was an error while loading. Please reload this page.

Closed

process: disallow adding options to process.allowedNodeEnvironmentFlags #36660

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
6262973
process: disallow adding options to process.allowedNodeEnvironmentFlags
aduh95 Dec 28, 2020
eafaa2b
fixup! process: disallow adding options to process.allowedNodeEnviron…
aduh95 Feb 1, 2021
466d928
fixup! fixup! process: disallow adding options to process.allowedNode…
aduh95 Feb 17, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

68 changes: 51 additions & 17 deletions 68 lib/internal/process/per_thread.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@

const {
ArrayPrototypeEvery,
ArrayPrototypeForEach,
ArrayPrototypeIncludes,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSplice,
BigUint64Array,
Float64Array,
NumberMAX_SAFE_INTEGER,
ObjectDefineProperty,
ObjectFreeze,
ReflectApply,
RegExpPrototypeTest,
SafeSet,
SafeArrayIterator,
Set,
SetPrototypeEntries,
SetPrototypeValues,
StringPrototypeEndsWith,
StringPrototypeReplace,
StringPrototypeSlice,
StringPrototypeStartsWith,
Symbol,
SymbolIterator,
Uint32Array,
} = primordials;

Expand All @@ -41,6 +47,8 @@ const {
} = require('internal/validators');
const constants = internalBinding('constants').os.signals;

const kInternal = Symbol('internal properties');

function assert(x, msg) {
if (!x) throw new ERR_ASSERTION(msg || 'assertion error');
}
Expand Down Expand Up @@ -293,18 +301,18 @@ function buildAllowedFlags() {

// Save these for comparison against flags provided to
// process.allowedNodeEnvironmentFlags.has() which lack leading dashes.
const nodeFlags = new SafeSet(ArrayPrototypeMap(allowedNodeEnvironmentFlags,
trimLeadingDashes));

class NodeEnvironmentFlagsSet extends SafeSet {
constructor(...args) {
super(...args);

// The super constructor consumes `add`, but
// disallow any future adds.
ObjectDefineProperty(this, 'add', {
value: () => this
});
const nodeFlags = ArrayPrototypeMap(allowedNodeEnvironmentFlags,
trimLeadingDashes);

class NodeEnvironmentFlagsSet extends Set {
constructor(array) {
super();
this[kInternal] = { array };
}

add() {
// No-op, `Set` API compatible
Comment thread Outdated

@jasnell jasnell Feb 1, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might seem silly but we need to at least consider whether there needs to be a deprecation cycle on this before it's made non-op.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@aduh95 aduh95 Feb 1, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that process.allowedNodeEnvironmentFlags.add is already no-op on all Node.js release lines.
We may or may not consider it a breaking change to make Set.prototype.add.call(process.allowedNodeEnvironmentFlags) no-op – IMHO we should not as this never was a documented thing, but no strong feelings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

benjamingr and jasnell reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
return this;
}

delete() {
Expand All @@ -313,7 +321,7 @@ function buildAllowedFlags() {
}

clear() {
// No-op
// No-op, `Set` API compatible
}

has(key) {
Expand All @@ -328,13 +336,39 @@ function buildAllowedFlags() {
key = StringPrototypeReplace(key, replaceUnderscoresRegex, '-');
if (RegExpPrototypeTest(leadingDashesRegex, key)) {
key = StringPrototypeReplace(key, trailingValuesRegex, '');
return super.has(key);
return ArrayPrototypeIncludes(this[kInternal].array, key);
}
return nodeFlags.has(key);
return ArrayPrototypeIncludes(nodeFlags, key);
}
return false;
}

entries() {
this[kInternal].set ??=
new Set(new SafeArrayIterator(this[kInternal].array));
return SetPrototypeEntries(this[kInternal].set);
}

forEach(callback, thisArg = undefined) {
ArrayPrototypeForEach(
this[kInternal].array,
(v) => ReflectApply(callback, thisArg, [v, v, this])
);
}

get size() {
return this[kInternal].array.length;
}

values() {
this[kInternal].set ??=
new Set(new SafeArrayIterator(this[kInternal].array));
return SetPrototypeValues(this[kInternal].set);
}
}
NodeEnvironmentFlagsSet.prototype.keys =
NodeEnvironmentFlagsSet.prototype[SymbolIterator] =
NodeEnvironmentFlagsSet.prototype.values;

ObjectFreeze(NodeEnvironmentFlagsSet.prototype.constructor);
ObjectFreeze(NodeEnvironmentFlagsSet.prototype);
Expand Down
39 changes: 33 additions & 6 deletions 39 test/parallel/test-process-env-allowed-flags.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

// Assert legit flags are allowed, and bogus flags are disallowed
Expand Down Expand Up @@ -63,14 +63,41 @@ const assert = require('assert');

process.allowedNodeEnvironmentFlags.add('foo');
assert.strictEqual(process.allowedNodeEnvironmentFlags.has('foo'), false);
process.allowedNodeEnvironmentFlags.forEach((flag) => {
assert.strictEqual(flag === 'foo', false);
});
Set.prototype.add.call(process.allowedNodeEnvironmentFlags, 'foo');
assert.strictEqual(process.allowedNodeEnvironmentFlags.has('foo'), false);

process.allowedNodeEnvironmentFlags.clear();
assert.strictEqual(process.allowedNodeEnvironmentFlags.size > 0, true);
const thisArg = {};
process.allowedNodeEnvironmentFlags.forEach(
common.mustCallAtLeast(function(flag, _, set) {
assert.notStrictEqual(flag, 'foo');
assert.strictEqual(this, thisArg);
assert.strictEqual(set, process.allowedNodeEnvironmentFlags);
}),
thisArg
);

for (const flag of process.allowedNodeEnvironmentFlags.keys()) {
assert.notStrictEqual(flag, 'foo');
}
for (const flag of process.allowedNodeEnvironmentFlags.values()) {
assert.notStrictEqual(flag, 'foo');
}
for (const flag of process.allowedNodeEnvironmentFlags) {
assert.notStrictEqual(flag, 'foo');
}
for (const [flag] of process.allowedNodeEnvironmentFlags.entries()) {
assert.notStrictEqual(flag, 'foo');
}

const size = process.allowedNodeEnvironmentFlags.size;

process.allowedNodeEnvironmentFlags.clear();
assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size);
Set.prototype.clear.call(process.allowedNodeEnvironmentFlags);
assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size);

process.allowedNodeEnvironmentFlags.delete('-r');
assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size);
Set.prototype.delete.call(process.allowedNodeEnvironmentFlags, '-r');
assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size);
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.