The vulnerability, as described, is a lockfile integrity bypass for remote dependencies like HTTP tarballs and git repositories. The root cause is that pnpm did not calculate and store an integrity hash for these dependencies in the lockfile. This would allow a malicious server to serve different, potentially malicious, content for the same dependency URL across different installations without pnpm detecting the change.
The analysis of the commits between the vulnerable and patched versions reveals the fix. The primary patch is in commit b7d3ec65b1024b7814179e862cb620779e78ff7a. It addresses the core issue by modifying the package fetching and storing process.
-
Integrity Calculation: The function addTarballToStore in worker/src/start.ts is modified to calculate a SHA-512 integrity hash of the tarball content if an integrity hash is not already present. This ensures that every fetched tarball has an associated integrity hash.
-
Integrity Propagation: The resolveAndFetch function in pkg-manager/package-requester/src/packageRequester.ts is updated to take this newly computed integrity hash and add it to the package's resolution data. This is the crucial step that ensures the integrity hash is written into the pnpm-lock.yaml file.
A secondary, related fix in commit 40775391d54d400c7d516bffaca667215a5e472d hardens the handling of git-hosted dependencies. The preparePackage function in exec/prepare-package/src/index.ts was modified to prevent the automatic execution of prepare scripts from git dependencies unless they are explicitly trusted via the onlyBuiltDependencies setting. This mitigates a related risk for one of the dependency types affected by the integrity bypass.
In summary, an exploit would involve a user installing a package with a malicious HTTP or git dependency. The identified vulnerable functions would be part of the pnpm's internal dependency resolution and fetching process that runs during pnpm install.