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,12 +73,9 @@ interface HookInput {
7573interface CheckResult {
7674 purl : string
7775 blocked ? : boolean
78- warned ? : boolean
7976 reason ? : string
80- score ? : number
8177}
8278
83-
8479// A cached API lookup result with expiration timestamp.
8580interface CacheEntry {
8681 result: CheckResult | undefined
@@ -324,14 +319,8 @@ async function check(hook: HookInput): Promise<number> {
324319 if ( deps . length === 0 ) return 0
325320
326321 // Check all deps via SDK checkMalware().
327- const { blocked, warned } = await checkDepsBatch ( deps )
322+ const blocked = await checkDepsBatch ( deps )
328323
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- }
335324 if ( blocked . length > 0 ) {
336325 logger . error ( `Socket: blocked ${ blocked . length } dep(s):` )
337326 for ( const b of blocked ) {
@@ -343,14 +332,11 @@ async function check(hook: HookInput): Promise<number> {
343332}
344333
345334// 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.
348335// Deps already in cache are skipped; results are cached after lookup.
349336async function checkDepsBatch (
350337 deps : Dep [ ] ,
351- ) : Promise < { blocked: CheckResult [ ] ; warned: CheckResult [ ] } > {
338+ ) : Promise < CheckResult [ ] > {
352339 const blocked : CheckResult [ ] = [ ]
353- const warned : CheckResult [ ] = [ ]
354340
355341 // Partition deps into cached vs uncached.
356342 const uncached : Array < { dep : Dep ; purl : string } > = [ ]
@@ -359,13 +345,12 @@ async function checkDepsBatch(
359345 const cached = cacheGet ( purl )
360346 if ( cached ) {
361347 if ( cached . result ?. blocked ) blocked . push ( cached . result )
362- else if ( cached . result ?. warned ) warned . push ( cached . result )
363348 continue
364349 }
365350 uncached . push ( { dep, purl } )
366351 }
367352
368- if ( ! uncached . length ) return { blocked , warned }
353+ if ( ! uncached . length ) return blocked
369354
370355 try {
371356 // Process in chunks to respect API batch size limit.
@@ -379,7 +364,7 @@ async function checkDepsBatch(
379364 logger . warn (
380365 `Socket: API returned ${ result . status } , allowing all`
381366 )
382- return { blocked, warned }
367+ return blocked
383368 }
384369
385370 // Build lookup keyed by full PURL (includes namespace + version).
@@ -395,37 +380,22 @@ async function checkDepsBatch(
395380 const purl = purlByKey.get(key)
396381 if (!purl) continue
397382
398- // Check for malware or critical-severity alerts.
399- const critical = pkg . alerts . find (
383+ // Check for malware alerts.
384+ const malware = pkg.alerts.find(
400385 a => a.severity === 'critical' || a.type === 'malware'
401386 )
402- if ( critical ) {
387+ if (malware ) {
403388 const cr: CheckResult = {
404389 purl,
405390 blocked: true,
406- reason : `${ critical . type } — ${ critical . severity ?? 'critical' } ` ,
391+ reason: ` $ { malware . type } — $ { malware . severity ?? 'critical' } `,
407392 }
408393 cacheSet(purl, cr)
409394 blocked.push(cr)
410395 continue
411396 }
412397
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.
398+ // No malware alerts — clean dep.
429399 cacheSet(purl, undefined)
430400 }
431401 }
@@ -437,7 +407,7 @@ async function checkDepsBatch(
437407 )
438408 }
439409
440- return { blocked, warned }
410+ return blocked
441411}
442412
443413// Return deps in ` newDeps ` that don't appear in ` oldDeps ` (by PURL).
0 commit comments