/

CVE-2026-57998

Severity:

HIGH RISK

(7.8)

OS Command Injection (CWE-78) in better-npm-audit

CVE-2026-57998

Deferred

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Arbitrary OS Command Execution

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

better-npm-audit constructs an npm audit command by inserting the user-supplied registry value into a shell command without validation or quoting. If an attacker can control this option, shell metacharacters may cause arbitrary operating system commands to execute with the audit process's privileges.

Affected context

The vulnerability occurs in better-npm-audit versions that build the npm audit command as a string and pass it to Node.js child_process.exec(), which invokes a shell. Risk is present when the --registry option can be influenced by an untrusted user, automation input, or another compromised process.

Exploit preconditions

  • Attack surface: The command-line or programmatic input that supplies the --registry option
  • Required access: Ability to provide or influence the registry value passed to the audit command
  • Trigger point: Construction and execution of the npm audit command
  • Why exploitation is possible: The value is interpolated into a shell command without adequate validation or quoting, allowing shell metacharacters to alter command interpretation

Why this happens

The underlying bug is an OS command injection flaw caused by combining untrusted input with a shell command string. Passing the resulting string to child_process.exec() enables shell interpretation of metacharacters rather than treating the registry value as a single data argument. This behavior maps to CWE-78, Improper Neutralization of Special Elements used in an OS Command.

Potential impact

  • An attacker may execute arbitrary operating system commands.
  • The audit process may be compromised with its available privileges.
  • Sensitive environment variables, files, or package metadata could be exposed.
  • The host or build environment could be altered, including through malware installation or data destruction.
  • Access to connected systems or credentials could enable further compromise.

General mitigation guidance

Mitigation generally focuses on removing shell interpretation from command

execution paths and reducing trust in command-line inputs.

Common defensive patterns include:

  • Use APIs that execute a program with an argument array rather than a shell, where supported.
  • Validate registry values against an explicit, narrowly defined format and accepted schemes or hosts.
  • Avoid constructing command strings through concatenation or interpolation.
  • Apply context-appropriate argument escaping when a shell is unavoidable.
  • Run audit processes with least privilege and restrict access to credentials and sensitive files.
  • Use isolated, minimally privileged build environments with constrained network and filesystem access.

How teams detect issues like this

Organizations can look for this weakness through:

  • Static analysis rules identifying untrusted input flowing into child_process.exec() or equivalent shell-spawning APIs.
  • Code review checks for string concatenation or template interpolation used to form OS commands.
  • Repository policies that require argument-array execution APIs for external processes.
  • Tests using benign metacharacter markers to verify that input remains a single argument, without executing arbitrary commands.
  • Runtime monitoring for unexpected child processes, command interpreters, or audit jobs accessing unrelated files and network destinations.

Automated code review and software composition analysis tools may help identify command-construction patterns, but should be supplemented with manual review.

Sources

SourceLink
github.comgithub.com/jeemok/better-npm-audit
github.comgithub.com/jeemok/better-npm-audit/blob/fd99a0f41ff4342b8a0a6fdbe5a17261de3d0544/index.ts#L34
github.comgithub.com/jeemok/better-npm-audit/blob/fd99a0f41ff4342b8a0a6fdbe5a17261de3d0544/src/handlers/handleInput.ts#L30-L37
github.comgithub.com/jeemok/better-npm-audit/issues/119
github.comgithub.com/jeemok/better-npm-audit/pull/120
vulncheck.comvulncheck.com/advisories/better-npm-audit-os-command-injection-via-registry-flag

Frequently asked

questions

It can be exploitable remotely when a network-facing service, automation system, or

integration accepts attacker-controlled registry input and invokes better-npm-audit.

In local-only usage, exploitation generally requires local access or control over

the inputs supplied to the process.

An attacker needs the ability to influence the --registry option, directly or

through a trusted wrapper, configuration source, or automated pipeline. The

attacker does not necessarily need an interactive shell on the affected host.

The safest pattern is to avoid shell execution and pass the registry value as a

separate process argument through an API that does not invoke a command shell.

Strict allowlist validation provides an additional boundary.

Treat command-line values as untrusted data, prohibit interpolated command

strings in code review and CI policy, use least-privilege execution, and monitor

child-process behavior for unexpected shell activity.

Find out what's already
exploitable in your codebase.