The project has migrated to pnpm but lacks strict enforcement and advanced security configurations. Recent usage of npm introduces risks of supply chain attacks (e.g., malicious install scripts).
Two articles were referenced for best practices:
- Zenn: Shai-Hulud infection check & Defense in Depth - Recommends
ignore-scripts. - DevelopersIO: pnpm migration pitfalls - Recommends
only-allow pnpm.
Establish a "Defense in Depth" strategy:
- Enforce pnpm: Prevent accidental use of
npmoryarnwhich might ignore lockfiles. - Disable Scripts: Enable
ignore-scriptsby default to block maliciouspreinstall/postinstallvectors. - Whitelist Trusted Builds: Explicitly allow necessary build scripts (e.g.,
esbuild) usingpnpm.onlyBuiltDependencies.
Note: minimum-release-age was considered but rejected due to friction with internal library updates.
- package.json:
- Add
"preinstall": "npx only-allow pnpm". - Add
pnpm.onlyBuiltDependenciesconfiguration.
- Add
- .npmrc:
- Create file with
ignore-scripts=true.
- Create file with
- Safety: Zero-day install-script attacks are neutralized by default.
- Consistency: Developers cannot use wrong package managers.
- Maintenance: New dependencies requiring build scripts must be explicitly allowlisted.
- Create
.npmrcwithignore-scripts=true - Add
only-allow pnpmtopackage.jsonscripts - Configure
pnpm.onlyBuiltDependenciesinpackage.jsonforesbuildand other valid tools - Verify
pnpm installworks with the new restrictions