The vulnerability exists because pnpm's security feature to disable dependency lifecycle scripts by default was not being applied to git-hosted dependencies. The core of the issue lies in the preparePackage function within exec/prepare-package/src/index.ts. This function is responsible for preparing git dependencies and was executing prepare, prepublish, and prepack scripts without checking against the onlyBuiltDependencies configuration that governs script execution.
The patch addresses this by introducing an allowBuild function that checks if a package is authorized to run build scripts. This check is added at the beginning of the preparePackage function. If a git-hosted dependency with a prepare script (or other lifecycle scripts) is not explicitly listed in onlyBuiltDependencies, the installation is now blocked, preventing the remote code execution vulnerability. The fix was propagated up the call stack to functions like gitFetcher to ensure the allowBuild setting is passed correctly during the package fetching phase.