/

CVE-2025-69262

Severity:

HIGH RISK

(7.5)

Command Injection in pnpm .npmrc

CVE-2025-69262

Analyzed

Vulnerability type

Category:

Command Injection

CWE:

CWE-78, CWE-94

Impact:

Remote Code Execution in build and automation environments

Severity:

HIGH RISK

(7.5)

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

pnpm versions 6.25.0 through 10.26.2 contain a command injection flaw in how environment variable substitution is handled for tokenHelper settings in .npmrc configuration files.

If an attacker can influence environment variables used during pnpm operations, they may be able to execute arbitrary commands in build or CI environments where pnpm runs.

Affected context

This vulnerability affects workflows where pnpm (versions 6.25.0–10.26.2) is used to install or manage packages, and .npmrc configuration relies on tokenHelper with environment-variable-based substitution.

It is especially relevant in:

  • CI/CD pipelines and automated build systems
  • Shared development environments with configurable environment variables
  • Scenarios where environment variables are derived from untrusted or partially trusted sources (e.g., user-controlled inputs, job parameters, or external configuration systems)

The risk materializes when pnpm evaluates tokenHelper commands that interpolate environment variables without adequately constraining or sanitizing them.

Exploit preconditions

  • Attack surface: pnpm execution context (e.g., CI runners, build agents, developer machines) that process .npmrc with a tokenHelper setting.
  • Required access:
  • Ability to influence or set environment variables used by .npmrc / tokenHelper (e.g., CI job variables, OS environment, container env vars), and
  • pnpm must be invoked in that environment (e.g., pnpm install, pnpm publish).
  • Trigger point: A pnpm operation that reads .npmrc and executes the configured tokenHelper, performing environment-variable substitution before or as part of command execution.
  • Why exploitation is possible: The tokenHelper mechanism treats substituted environment-variable content as part of a shell command without robust validation or separation between data and executable code, enabling crafted values to break out of the intended command structure and inject arbitrary shell instructions.

Why this happens

The root cause lies in the way pnpm handles environment-variable substitution in .npmrc for tokenHelper configuration.

Instead of treating environment-variable content purely as data, the implementation allows it to be interpolated into command strings that are executed, mapping to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

When the boundary between configuration data and executable shell syntax is blurred, an attacker-controlled environment variable can introduce shell metacharacters or additional commands.

In some setups, this behavior also intersects with CWE-94: Improper Control of Generation of Code, where dynamic construction of executable statements is influenced by configuration or environment values.

Potential impact

  • Remote Code Execution (RCE) within CI/CD runners or build agents where pnpm is executed
  • Unauthorized modification of build artifacts, lockfiles, or packaged outputs
  • Leakage of sensitive data available to the build environment (tokens, secrets, SSH keys, service credentials)
  • Lateral movement inside the build infrastructure or associated container/orchestration platform
  • Tampering with supply-chain outputs, including insertion of malicious logic into published packages

General mitigation guidance

Effective mitigation focuses on separating configuration data from executable commands and reducing trust in environment-derived values:

  • Prefer authentication mechanisms that do not rely on shell-executed helpers where possible (e.g., static tokens managed by secure secret stores or native auth mechanisms).
  • Avoid dynamic command construction in .npmrc tokenHelper entries, especially ones that interpolate environment variables directly into shell commands.
  • Restrict which environment variables can influence pnpm in build environments; ensure untrusted user inputs are not mapped directly to environment variables used in authentication or helper commands.
  • Apply least-privilege principles to CI/CD and build agents so that, even if command injection occurs, the process has limited access to secrets, file systems, and network resources.
  • Use secure-by-default configuration templates for .npmrc that minimize or eliminate shell-based helpers where not strictly necessary.

How teams detect issues like this

Detection efforts can combine configuration review with automated analysis:

  • Static configuration review: Examine .npmrc (and any project- or user-level configuration) for tokenHelper entries that:
  • Invoke shell commands, and
  • Incorporate environment variable placeholders or templating syntax in ways that could introduce shell metacharacters.
  • Code and pipeline review: Review CI/CD pipeline definitions (YAML, scripts) to identify environment variables that:
  • Are derived from user or external input, and
  • Are consumed by pnpm or .npmrc token helpers.
  • Static analysis / linters: Apply custom rules in SAST or configuration-linting tools to flag patterns like:
  • Shell interpolation using environment variables in .npmrc or pnpm-related scripts.
  • Use of generic shell execution APIs in tooling that handle auth tokens.
  • Runtime monitoring: In high-security environments, monitor build agents for unexpected child processes or command patterns spawned during pnpm operations.

Automated security scanning tools integrated into CI can help identify high-risk configuration combinations before they reach production pipelines.

Sources

SourceLink
github.comgithub.com/pnpm/pnpm/releases/tag/v10.27.0
github.comgithub.com/pnpm/pnpm/security/advisories/GHSA-2phv-j68v-wwqx

Frequently asked

questions

Yes, in many setups it can be exploited remotely, but only indirectly.

An attacker typically interacts with a system that configures environment variables (such as a CI job interface, deployment pipeline, or external configuration source).

When pnpm subsequently runs in that environment and processes .npmrc with a vulnerable tokenHelper, the attacker's input can lead to command execution.

The attacker needs influence over environment variables evaluated by pnpm's tokenHelper configuration (for example, CI variables, environment configuration parameters, or other settings that are mapped directly into env vars).

They do not necessarily need direct shell access, but they must be able to control values that pnpm will substitute into the helper command.

The safest pattern is to eliminate or strictly constrain shell-based token helpers that interpolate environment variables.

Use mechanisms that treat tokens as opaque data, avoid dynamic command building, and ensure helper execution does not depend on untrusted environment input.

Where helper commands are unavoidable, design them to accept data via arguments or standard input rather than via command-string interpolation.

To prevent similar vulnerabilities, treat all environment-variable content as untrusted by default, avoid building shell commands through string concatenation or interpolation, and favor APIs that separate code from data.

Enforce secure configuration guidelines for .npmrc and other tooling configs, integrate configuration linting and SAST checks into CI pipelines, and apply least-privilege to build agents so that misconfigurations cannot easily escalate into severe supply-chain compromises.

Find out what's already
exploitable in your codebase.