Skip to content

Commit 3593433

Browse files
committed
feat(node): add SIGUSR1 signal handler prevention flags
Add support for disabling SIGUSR1 debugger signal handling in production: - supportsNodeDisableSigusr1Flag(): Detects flag support (v22.14+, v23.7+, v24.8+) - getNodeDisableSigusr1Flags(): Returns --disable-sigusr1 or --no-inspect fallback SIGUSR1 is reserved by Node.js for starting the debugger/inspector. In production CLI environments, we prevent debugger attachment for security. --disable-sigusr1: Proper solution (prevents Signal I/O Thread creation entirely) --no-inspect: Fallback for Node 18+ (still creates thread but blocks later)
1 parent 3df0fea commit 3593433

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/constants/node.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ export function supportsNodeRun(): boolean {
7777
)
7878
}
7979

80+
export function supportsNodeDisableSigusr1Flag(): boolean {
81+
const major = getNodeMajorVersion()
82+
// --disable-sigusr1 added in v22.14.0, v23.7.0.
83+
// Stabilized in v22.20.0, v24.8.0.
84+
if (major >= 24) {
85+
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
86+
return minor >= 8
87+
}
88+
if (major === 23) {
89+
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
90+
return minor >= 7
91+
}
92+
if (major === 22) {
93+
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
94+
return minor >= 14
95+
}
96+
return false
97+
}
98+
99+
let _nodeDisableSigusr1Flags: string[]
100+
export function getNodeDisableSigusr1Flags(): string[] {
101+
if (_nodeDisableSigusr1Flags === undefined) {
102+
// SIGUSR1 is reserved by Node.js for starting the debugger/inspector.
103+
// In production CLI environments, we want to prevent debugger attachment.
104+
//
105+
// --disable-sigusr1: Prevents Signal I/O Thread from listening to SIGUSR1 (v22.14.0+).
106+
// --no-inspect: Disables inspector on older Node versions that don't support --disable-sigusr1.
107+
//
108+
// Note: --disable-sigusr1 is the correct solution (prevents thread creation entirely).
109+
// --no-inspect is a fallback that still creates the signal handler thread but blocks later.
110+
_nodeDisableSigusr1Flags = supportsNodeDisableSigusr1Flag()
111+
? ['--disable-sigusr1']
112+
: ['--no-inspect']
113+
}
114+
return _nodeDisableSigusr1Flags
115+
}
116+
80117
export function supportsProcessSend(): boolean {
81118
return typeof process.send === 'function'
82119
}

0 commit comments

Comments
 (0)