From 472f58684055a15b465e02466548df5def4ed640 Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Mon, 22 Dec 2025 17:14:46 +0100 Subject: [PATCH] os: freeze signals constant Remove the ability to mutate signals constant as doing so can lead to unexpected behavior, notably when spawning child process. Fixes: https://github.com/nodejs/node/issues/44749 PR-URL: https://github.com/nodejs/node/pull/61038 Reviewed-By: Yagiz Nizipli Reviewed-By: Aviv Keller --- lib/os.js | 3 +++ test/parallel/test-os-constants-signals.js | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/parallel/test-os-constants-signals.js diff --git a/lib/os.js b/lib/os.js index 9f062fea04d..5e53879bd6d 100644 --- a/lib/os.js +++ b/lib/os.js @@ -25,6 +25,7 @@ const { ArrayPrototypePush, Float64Array, ObjectDefineProperties, + ObjectFreeze, StringPrototypeSlice, SymbolToPrimitive, } = primordials; @@ -330,6 +331,8 @@ module.exports = { machine: getMachine, }; +ObjectFreeze(constants.signals); + ObjectDefineProperties(module.exports, { constants: { __proto__: null, diff --git a/test/parallel/test-os-constants-signals.js b/test/parallel/test-os-constants-signals.js new file mode 100644 index 00000000000..a4fac1b6356 --- /dev/null +++ b/test/parallel/test-os-constants-signals.js @@ -0,0 +1,11 @@ +'use strict'; + +require('../common'); +const { test } = require('node:test'); +const assert = require('node:assert'); +const { constants } = require('node:os'); + + +test('Verify that signals constant is immutable', () => { + assert.throws(() => constants.signals.FOOBAR = 1337, TypeError); +});