1515//
1616// Exit codes:
1717// 0 = allow (no new deps, all clean, or non-dep file)
18- // 2 = block (malware or critical alert from Socket.dev)
18+ // 2 = block (malware detected by Socket.dev)
1919
2020import {
2121 parseNpmSpecifier ,
@@ -36,8 +36,6 @@ const logger = getDefaultLogger()
3636
3737// Per-request timeout (ms) to avoid blocking the hook on slow responses.
3838const API_TIMEOUT = 5_000
39- // Deps scoring below this threshold trigger a warning (not a block).
40- const LOW_SCORE_THRESHOLD = 0.5
4139// Max PURLs per batch request (API limit is 1024).
4240const MAX_BATCH_SIZE = 1024
4341// How long (ms) to cache a successful API response (5 minutes).
@@ -75,9 +73,7 @@ interface HookInput {
7573interface CheckResult {
7674 purl : string
7775 blocked ? : boolean
78- warned ? : boolean
7976 reason ? : string
80- score ? : number
8177}
8278
8379
@@ -324,14 +320,8 @@ async function check(hook: HookInput): Promise<number> {
324320 if ( deps . length === 0 ) return 0
325321
326322 // Check all deps via SDK checkMalware().
327- const { blocked, warned } = await checkDepsBatch ( deps )
323+ const blocked = await checkDepsBatch ( deps )
328324
329- if ( warned . length > 0 ) {
330- logger . warn ( 'Socket: low-scoring dependencies (not blocked):' )
331- for ( const w of warned ) {
332- logger . warn ( ` ${ w . purl } : overall score ${ w . score } ` )
333- }
334- }
335325 if ( blocked . length > 0 ) {
336326 logger . error ( `Socket: blocked ${ blocked . length } dep(s):` )
337327 for ( const b of blocked ) {
@@ -343,14 +333,11 @@ async function check(hook: HookInput): Promise<number> {
343333}
344334
345335// Check deps against Socket.dev using SDK v4 checkMalware().
346- // The SDK automatically routes small sets (<=5) to parallel firewall
347- // requests and larger sets to the batch PURL API.
348336// Deps already in cache are skipped; results are cached after lookup.
349337async function checkDepsBatch (
350338 deps : Dep [ ] ,
351- ) : Promise < { blocked: CheckResult [ ] ; warned: CheckResult [ ] } > {
339+ ) : Promise < CheckResult [ ] > {
352340 const blocked : CheckResult [ ] = [ ]
353- const warned : CheckResult [ ] = [ ]
354341
355342 // Partition deps into cached vs uncached.
356343 const uncached : Array < { dep : Dep ; purl : string } > = [ ]
@@ -359,13 +346,12 @@ async function checkDepsBatch(
359346 const cached = cacheGet ( purl )
360347 if ( cached ) {
361348 if ( cached . result ?. blocked ) blocked . push ( cached . result )
362- else if ( cached . result ?. warned ) warned . push ( cached . result )
363349 continue
364350 }
365351 uncached . push ( { dep, purl } )
366352 }
367353
368- if ( ! uncached . length ) return { blocked , warned }
354+ if ( ! uncached . length ) return blocked
369355
370356 try {
371357 // Process in chunks to respect API batch size limit.
@@ -379,7 +365,7 @@ async function checkDepsBatch(
379365 logger . warn (
380366 `Socket: API returned ${ result . status } , allowing all`
381367 )
382- return { blocked, warned }
368+ return blocked
383369 }
384370
385371 // Build lookup keyed by full PURL (includes namespace + version).
@@ -395,37 +381,22 @@ async function checkDepsBatch(
395381 const purl = purlByKey.get(key)
396382 if (!purl) continue
397383
398- // Check for malware or critical-severity alerts.
399- const critical = pkg . alerts . find (
384+ // Check for malware alerts.
385+ const malware = pkg.alerts.find(
400386 a => a.severity === 'critical' || a.type === 'malware'
401387 )
402- if ( critical ) {
388+ if (malware ) {
403389 const cr: CheckResult = {
404390 purl,
405391 blocked: true,
406- reason : `${ critical . type } — ${ critical . severity ?? 'critical' } ` ,
392+ reason: ` $ { malware . type } — $ { malware . severity ?? 'critical' } `,
407393 }
408394 cacheSet(purl, cr)
409395 blocked.push(cr)
410396 continue
411397 }
412398
413- // Warn on low quality score.
414- if (
415- pkg . score ?. overall !== undefined
416- && pkg . score . overall < LOW_SCORE_THRESHOLD
417- ) {
418- const wr : CheckResult = {
419- purl,
420- warned : true ,
421- score : pkg . score . overall ,
422- }
423- cacheSet ( purl , wr )
424- warned . push ( wr )
425- continue
426- }
427-
428- // No blocking alerts — clean dep.
399+ // No malware alerts — clean dep.
429400 cacheSet(purl, undefined)
430401 }
431402 }
@@ -437,7 +408,7 @@ async function checkDepsBatch(
437408 )
438409 }
439410
440- return { blocked, warned }
411+ return blocked
441412}
442413
443414// Return deps in ` newDeps ` that don't appear in ` oldDeps ` (by PURL).
0 commit comments