From e74a8da287329d5d1901b698029ef6c2dc75c5fd Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 2 May 2022 19:46:24 +0200 Subject: [PATCH] assert: make `assert.fail` less affected by prototype tampering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/42918 Reviewed-By: Michaƫl Zasso Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Colin Ihrig --- lib/internal/assert/assertion_error.js | 1 + test/parallel/test-assert-fail.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 837c37b1221540..e160d6d7e868eb 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -441,6 +441,7 @@ class AssertionError extends Error { this.generatedMessage = !message; ObjectDefineProperty(this, 'name', { + __proto__: null, value: 'AssertionError [ERR_ASSERTION]', enumerable: false, writable: true, diff --git a/test/parallel/test-assert-fail.js b/test/parallel/test-assert-fail.js index e2003f2ce91da8..37e2087a2fdc72 100644 --- a/test/parallel/test-assert-fail.js +++ b/test/parallel/test-assert-fail.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); // No args @@ -38,3 +38,7 @@ assert.throws(() => { name: 'TypeError', message: 'custom message' }); + +Object.prototype.get = common.mustNotCall(); +assert.throws(() => assert.fail(''), { code: 'ERR_ASSERTION' }); +delete Object.prototype.get;