(node, policy)
| 24 | // resolved committish |
| 25 | |
| 26 | const 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 | |
| 71 | const matches = (node, key, failClosed) => { |
| 72 | let parsed |
no test coverage detected