Skip to content

Commit c6193fe

Browse files
BridgeARBethGriggs
authored andcommittedFeb 6, 2020
util: never trigger any proxy traps using format()
Backport-PR-URL: #31431 PR-URL: #30767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 963c14c commit c6193fe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
 

‎lib/internal/util/inspect.js

+7
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,13 @@ function format(...args) {
16461646
}
16471647

16481648
function hasBuiltInToString(value) {
1649+
// Prevent triggering proxy traps.
1650+
const getFullProxy = false;
1651+
const proxyTarget = getProxyDetails(value, getFullProxy);
1652+
if (proxyTarget !== undefined) {
1653+
value = proxyTarget;
1654+
}
1655+
16491656
// Count objects that have no `toString` function as built-in.
16501657
if (typeof value.toString !== 'function') {
16511658
return true;

‎test/parallel/test-util-inspect-proxy.js

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ proxyObj = new Proxy(target, handler);
4141
// Inspecting the proxy should not actually walk it's properties
4242
util.inspect(proxyObj, opts);
4343

44+
// Make sure inspecting object does not trigger any proxy traps.
45+
util.format('%s', proxyObj);
46+
4447
// getProxyDetails is an internal method, not intended for public use.
4548
// This is here to test that the internals are working correctly.
4649
let details = processUtil.getProxyDetails(proxyObj, true);

0 commit comments

Comments
 (0)
Please sign in to comment.