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
.npmrcwith atokenHelpersetting. - 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
.npmrcand executes the configuredtokenHelper, performing environment-variable substitution before or as part of command execution. - Why exploitation is possible: The
tokenHelpermechanism 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
.npmrctokenHelperentries, 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
.npmrcthat 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) fortokenHelperentries 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
.npmrctoken helpers. - Static analysis / linters: Apply custom rules in SAST or configuration-linting tools to flag patterns like:
- Shell interpolation using environment variables in
.npmrcor 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
pnpmoperations.
Automated security scanning tools integrated into CI can help identify high-risk configuration combinations before they reach production pipelines.

