GHSA-379q-355j-w6rj: pnpm v10+ Bypass "Dependency lifecycle scripts execution disabled by default"
pnpm v10+ Git Dependency Script Execution BypassSummaryA security bypass vulnerability in pnpm v10+ allows git-hosted dependencies to execute arbitrary code during `pnpm install`, circumventing the v10 security feature "Dependency lifecycle scripts execution disabled by default". While pnpm v10 blocks `postinstall` scripts via the `onlyBuiltDependencies` mechanism, git dependencies can still execute `prepare`, `prepublish`, and `prepack` scripts during the fetch phase, enabling remote code execution without user consent or approval.Detailspnpm v10 introduced a security feature to disable dependency lifecycle scripts by default ([PR #8897](https://github.com/pnpm/pnpm/pull/8897)). This is implemented by setting `onlyBuiltDependencies = []` when no build policy is configured:**File:** `pkg-manager/core/src/install/extendInstallOptions.ts` (lines 290-291)This creates an allowlist that blocks all packages from running scripts during the **BUILD phase** in `exec/build-modules/src/index.ts`.However, git-hosted dependencies are processed differently. During the **FETCH phase**, git packages are prepared using `preparePackage()`:**File:** `exec/prepare-package/src/index.ts` (lines 28-57)The `ignoreScripts` option defaults to `false` and is completely separate from `onlyBuiltDependencies`. The `onlyBuiltDependencies` allowlist is never consulted during the fetch phase.**Affected scripts that execute during fetch:**`prepare``prepublish``prepack`**Attack vectors:**`git+https://github.com/attacker/malicious.git``github:attacker/malicious``gitlab:attacker/malicious``bitbucket:attacker/malicious``git+ssh://git@github.com/attacker/malicious.git``git+file:///path/to/local/repo`PoC**Prerequisites:**pnpm v10.0.0 or later (tested on v10.23.0 and v11.0.0-alpha.1)git**Steps to reproduce:**Extract the attached [poc.zip](https://github.com/user-attachments/files/23797816/poc.zip)Run the PoC script:Verify the marker file was created by the malicious script:**Manual reproduction:**Create a malicious package with a `prepare` script:Initialize it as a git repo and commit the filesCreate a victim project that depends on it (just have to make sure it actually git clones and not just downloads a tarball):Run `pnpm install` - the prepare script executes without any warning or approval promptImpact**Severity: High****Who is impacted:**All pnpm v10+ usersUsers who believed they were protected by the v10 "scripts disabled by default" featureCI/CD pipelines**Attack scenarios:****Supply chain attack:** An attacker compromises a dependency, adding to it a malicious git dependency that executes arbitrary code during `pnpm install`**What an attacker can do:**Execute arbitrary code with the victim's privilegesExfiltrate environment variables, secrets, and credentialsModify source code or inject backdoorsEstablish persistence or reverse shellsAccess the filesystem and network**Why this bypasses security expectations:**pnpm v10 changelog explicitly states "Lifecycle scripts of dependencies are not executed during installation by default"Users expect git dependencies to follow the same security model as npm registry packagesThere is no warning that git dependencies are treated differentlyThe `onlyBuiltDependencies` configuration does not affect git dependencies
CVSS v3.1: 8.8