@@ -229,6 +229,57 @@ t.test('omitLockfileRegistryResolved: name-only match via edges; version-pinned
229229 t . end ( )
230230} )
231231
232+ t . test ( 'omitLockfileRegistryResolved: version-pinned deny fails closed' , t => {
233+ // No resolved URL means no trusted version. A version-pinned deny must
234+ // still block (fail closed); a matching allow stays refused.
235+ const omitted = ( ) => ( {
236+ name : 'evilpkg' ,
237+ packageName : 'evilpkg' ,
238+ version : '1.0.0' ,
239+ resolved : undefined ,
240+ location : 'node_modules/evilpkg' ,
241+ edgesIn : new Set ( [ { name : 'evilpkg' , spec : '^1.0.0' } ] ) ,
242+ } )
243+
244+ // Exact-version deny: blocked.
245+ t . equal ( isScriptAllowed ( omitted ( ) , { '[email protected] ' :
false } ) , false , 246+ 'version-pinned deny blocks even without a trusted version' )
247+ // Exact-disjunction deny: blocked.
248+ t . equal ( isScriptAllowed ( omitted ( ) , { '[email protected] || 2.0.0' :
false } ) , false , 249+ 'exact-disjunction deny blocks even without a trusted version' )
250+ // The exploit: name-only allow + version-pinned deny. Deny still wins.
251+ t . equal ( isScriptAllowed ( omitted ( ) , { evilpkg :
true , '[email protected] ' :
false } ) , false , 252+ 'deny wins over a name-only allow when the version is unverifiable' )
253+
254+ // Allow stays strict: an unverifiable version is never authorized.
255+ t . equal ( isScriptAllowed ( omitted ( ) , { '[email protected] || 2.0.0' :
true } ) , null , 256+ 'exact-disjunction allow is refused without a trusted version' )
257+
258+ // Name mismatch: fail-closed must not over-match a different package.
259+ t . equal ( isScriptAllowed ( omitted ( ) , { '[email protected] ' :
false } ) , null , 260+ 'a version-pinned deny for a different name does not match' )
261+
262+ t . end ( )
263+ } )
264+
265+ t . test ( 'omitLockfileRegistryResolved + alias: version-pinned deny fails closed' , t => {
266+ // `"trusted": "npm:[email protected] "`, resolved omitted. A deny on the 267+ // underlying name must block; the alias name authorizes nothing.
268+ const aliasOmitted = {
269+ name : 'trusted' ,
270+ packageName : 'naughty' ,
271+ version : '1.0.0' ,
272+ resolved : undefined ,
273+ location : 'node_modules/trusted' ,
274+ edgesIn :
new Set ( [ { name :
'trusted' , spec :
'npm:[email protected] ' } ] ) , 275+ }
276+ t . equal ( isScriptAllowed ( aliasOmitted , { '[email protected] ' :
false } ) , false , 277+ 'underlying-name version deny blocks the aliased package' )
278+ t . equal ( isScriptAllowed ( aliasOmitted , { '[email protected] ' :
false } ) , null , 279+ 'alias-name version deny does not match the underlying package' )
280+ t . end ( )
281+ } )
282+
232283t . test ( 'omitLockfileRegistryResolved + alias: location is ignored; underlying name wins' , t => {
233284 // Consumer's package.json has `"trusted": "npm:[email protected] "`. With 234285 // omitLockfileRegistryResolved, the resolved URL is absent. The install
0 commit comments