diff options
author | Rich Trott <rtrott@gmail.com> | 2019-02-05 15:41:18 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-02-10 12:51:38 -0800 |
commit | 1847696f4b6284bad45f452bc8595927074118dc (patch) | |
tree | bc4999e8cf4363569f5182d68354b360a0f3e287 /lib | |
parent | ba4df925eb7143606d5a57f49e4ecb179dd7743b (diff) | |
download | android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.tar.gz android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.tar.bz2 android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.zip |
util: protect against monkeypatched Object prototype for inspect()
Prevent affects of monkeypatching (for example) Object.keys() when
calling util.inspect().
PR-URL: https://github.com/nodejs/node/pull/25953
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/util/inspect.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 0f81ab5d02..94d6ef8706 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -63,6 +63,11 @@ const { isBigUint64Array } = require('internal/util/types'); +const assert = require('internal/assert'); + +// Avoid monkey-patched built-ins. +const { Object } = primordials; + const ReflectApply = Reflect.apply; // This function is borrowed from the function with the same name on V8 Extras' @@ -383,13 +388,9 @@ function getKeys(value, showHidden) { try { keys = Object.keys(value); } catch (err) { - if (isNativeError(err) && - err.name === 'ReferenceError' && - isModuleNamespaceObject(value)) { - keys = Object.getOwnPropertyNames(value); - } else { - throw err; - } + assert(isNativeError(err) && err.name === 'ReferenceError' && + isModuleNamespaceObject(value)); + keys = Object.getOwnPropertyNames(value); } if (symbols.length !== 0) { keys.push(...symbols.filter((key) => propertyIsEnumerable(value, key))); |