mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
util: harden more built-in classes against prototype pollution
PR-URL: https://github.com/nodejs/node/pull/56225 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
parent
b171afefb6
commit
80e3ef38ee
3 changed files with 67 additions and 4 deletions
|
@ -35,6 +35,7 @@ const {
|
|||
NumberMIN_SAFE_INTEGER,
|
||||
ObjectDefineProperties,
|
||||
ObjectDefineProperty,
|
||||
ObjectPrototypeHasOwnProperty,
|
||||
ObjectSetPrototypeOf,
|
||||
RegExpPrototypeSymbolReplace,
|
||||
StringPrototypeCharCodeAt,
|
||||
|
@ -911,7 +912,14 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
|
|||
}), 27, -2);
|
||||
}
|
||||
}
|
||||
return `<${this.constructor.name} ${str}>`;
|
||||
let constructorName = 'Buffer';
|
||||
try {
|
||||
const { constructor } = this;
|
||||
if (typeof constructor === 'function' && ObjectPrototypeHasOwnProperty(constructor, 'name')) {
|
||||
constructorName = constructor.name;
|
||||
}
|
||||
} catch { /* Ignore error and use default name */ }
|
||||
return `<${constructorName} ${str}>`;
|
||||
};
|
||||
Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue