Corepack (packageManager field)
Transparently, when package manager commands are mediated through Corepack
- Lives in
"packageManager" field in package.json, COREPACK_HOME cache directory- Attacker needs
- Supply-chain foothold, Registry / config control
- Lifecycle
- InstallStartupyour codeModule loadRuntimeREPL
Runs while dependencies download and build. The app has never started.
How it runs
Corepack is a transparent proxy for package managers. It reads the "packageManager" field in package.json, then downloads and runs the specified version of yarn, pnpm, or npm.
{ "packageManager": "yarn@4.5.0" }
When Corepack is enabled, it sits between you and yarn install. It makes sure the pinned version is available, downloads it if needed, and executes it. The weak point is the field itself. Anyone who can modify package.json can point it at a malicious package-manager version. Corepack fetches from the npm registry by default, so a typosquatted name resolves the same way any other npm package does.
COREPACK_HOME controls the cache directory, and poisoning it backdoors every project on the machine. Custom-URL fetches via corepack prepare skip the known-good integrity list entirely. And because Corepack intercepts the package manager binary, a compromised version controls the entire install pipeline. That includes resolution, lifecycle scripts and lockfile generation.
Defend
Pin and review the packageManager field; protect COREPACK_HOME; avoid corepack prepare from custom URLs; prefer known-good official versions.