MCPcopy Create free account
hub / github.com/npm/cli / isScriptAllowed

Function isScriptAllowed

workspaces/arborist/lib/script-allowed.js:26–69  ·  view source on GitHub ↗
(node, policy)

Source from the content-addressed store, hash-verified

24// resolved committish
25
26const isScriptAllowed = (node, policy) => {
27 // Bundled dependencies never run their install scripts and cannot be
28 // allowlisted. Matching by name@version from the bundled tarball would
29 // reintroduce manifest confusion (a bundled tarball can claim any name
30 // and version). Returning null marks them as not-allowed regardless of
31 // any policy entry, so their install scripts are blocked by the
32 // install-time gate. A package that needs a bundled dep's script must
33 // forward it as one of its own lifecycle scripts.
34 if (node.inBundle) {
35 return null
36 }
37
38 if (!policy || typeof policy !== 'object') {
39 return null
40 }
41
42 let anyAllow = false
43 let anyDeny = false
44
45 for (const [key, value] of Object.entries(policy)) {
46 // Pass deny intent so matchRegistry can fail closed on an unverifiable
47 // version: a deny still blocks, an allow stays refused.
48 if (!matches(node, key, value === false)) {
49 continue
50 }
51 if (value === false) {
52 anyDeny = true
53 continue
54 }
55 /* istanbul ignore else: policy values are strictly true/false;
56 defensive guard against unexpected coercions. */
57 if (value === true) {
58 anyAllow = true
59 }
60 }
61
62 if (anyDeny) {
63 return false
64 }
65 if (anyAllow) {
66 return true
67 }
68 return null
69}
70
71const matches = (node, key, failClosed) => {
72 let parsed

Callers 3

collectUnreviewedScriptsFunction · 0.85
#buildQueuesMethod · 0.85
script-allowed.jsFile · 0.85

Calls 1

matchesFunction · 0.85

Tested by

no test coverage detected