-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: disallow some uses of Object.defineProperty() on process.env
Disallow the use of Object.defineProperty() to hide entries in process.env or make them immutable. PR-URL: #28006 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
- Loading branch information
Showing
6 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
process.env.foo = 'foo'; | ||
assert.strictEqual(process.env.foo, 'foo'); | ||
process.env.foo = undefined; | ||
assert.strictEqual(process.env.foo, 'undefined'); | ||
|
||
process.env.foo = 'foo'; | ||
assert.strictEqual(process.env.foo, 'foo'); | ||
delete process.env.foo; | ||
assert.strictEqual(process.env.foo, undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert.throws( | ||
() => { | ||
Object.defineProperty(process.env, 'foo', { | ||
value: 'foo1' | ||
}); | ||
}, | ||
{ | ||
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', | ||
name: 'TypeError', | ||
message: '\'process.env\' only accepts a ' + | ||
'configurable, writable,' + | ||
' and enumerable data descriptor' | ||
} | ||
); | ||
|
||
assert.strictEqual(process.env.foo, undefined); | ||
process.env.foo = 'foo2'; | ||
assert.strictEqual(process.env.foo, 'foo2'); | ||
|
||
assert.throws( | ||
() => { | ||
Object.defineProperty(process.env, 'goo', { | ||
get() { | ||
return 'goo'; | ||
}, | ||
set() {} | ||
}); | ||
}, | ||
{ | ||
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', | ||
name: 'TypeError', | ||
message: '\'process.env\' does not accept an' + | ||
'accessor(getter/setter) descriptor' | ||
} | ||
); | ||
|
||
const attributes = ['configurable', 'writable', 'enumerable']; | ||
|
||
attributes.forEach((attribute) => { | ||
assert.throws( | ||
() => { | ||
Object.defineProperty(process.env, 'goo', { | ||
[attribute]: false | ||
}); | ||
}, | ||
{ | ||
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', | ||
name: 'TypeError', | ||
message: '\'process.env\' only accepts a ' + | ||
'configurable, writable,' + | ||
' and enumerable data descriptor' | ||
} | ||
); | ||
}); | ||
|
||
assert.strictEqual(process.env.goo, undefined); | ||
Object.defineProperty(process.env, 'goo', { | ||
value: 'goo', | ||
configurable: true, | ||
writable: true, | ||
enumerable: true | ||
}); | ||
assert.strictEqual(process.env.goo, 'goo'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters