Skip to content

Commit c0f39b9

Browse files
committed
feat(pnpm): block untrusted package postinstall scripts by default
1 parent 0f22da5 commit c0f39b9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scopes/dependencies/pnpm/lynx.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ import { isEqual } from 'lodash';
4040
import { pnpmErrorToBitError } from './pnpm-error-to-bit-error';
4141
import { readConfig } from './read-config';
4242

43+
/**
44+
* Packages that are known to have risky or unnecessary build scripts.
45+
* These packages will be disallowed from running scripts by default,
46+
* unless the user explicitly allows them in `allowScripts`.
47+
*/
48+
const UNTRUSTED_PACKAGE_NAMES = ['es5-ext', 'less', 'protobufjs', 'ssh', 'core-js-pure', 'core-js'];
49+
4350
const installsRunning: Record<string, Promise<any>> = {};
4451
const cafsLocker = new Map<string, number>();
4552

@@ -425,6 +432,12 @@ function resolveScriptPolicies({
425432
onlyBuiltDependencies.push(trustedPkgName);
426433
}
427434
}
435+
// Add untrusted packages to ignoredBuiltDependencies unless the user explicitly allows them
436+
for (const untrustedPkgName of UNTRUSTED_PACKAGE_NAMES) {
437+
if (allowScripts?.[untrustedPkgName] !== true) {
438+
ignoredBuiltDependencies.push(untrustedPkgName);
439+
}
440+
}
428441
}
429442

430443
return { neverBuiltDependencies: resolvedNeverBuilt, onlyBuiltDependencies, ignoredBuiltDependencies };

0 commit comments

Comments
 (0)