Skip to content

Commit e74a8da

Browse files
aduh95RafaelGSS
authored andcommitted
assert: make assert.fail less affected by prototype tampering
PR-URL: #42918 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 88692d8 commit e74a8da

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/assert/assertion_error.js

+1
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ class AssertionError extends Error {
441441

442442
this.generatedMessage = !message;
443443
ObjectDefineProperty(this, 'name', {
444+
__proto__: null,
444445
value: 'AssertionError [ERR_ASSERTION]',
445446
enumerable: false,
446447
writable: true,

test/parallel/test-assert-fail.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
// No args
@@ -38,3 +38,7 @@ assert.throws(() => {
3838
name: 'TypeError',
3939
message: 'custom message'
4040
});
41+
42+
Object.prototype.get = common.mustNotCall();
43+
assert.throws(() => assert.fail(''), { code: 'ERR_ASSERTION' });
44+
delete Object.prototype.get;

0 commit comments

Comments
 (0)