Skip to content

Commit ebb9c49

Browse files
authored
fix: clean up check-new-deps hook (#595)
Remove low-score warnings and fix inaccurate comments. The malware API only checks for malware, not quality scores. Remove dead warned/score logic and the wrong SDK batch heuristic comment.
1 parent 4e40891 commit ebb9c49

3 files changed

Lines changed: 88 additions & 49 deletions

File tree

.claude/hooks/check-new-deps/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ When Claude edits a file like `package.json`, `requirements.txt`, `Cargo.toml`,
88

99
1. **Detects the file type** and extracts dependency names from the content
1010
2. **Diffs against the old content** (for edits) so only *newly added* deps are checked
11-
3. **Queries the Socket.dev API** to check for malware and critical security alerts
12-
4. **Blocks the edit** (exit code 2) if malware or critical alerts are found
13-
5. **Warns** (but allows) if a package has a low quality score
14-
6. **Allows** (exit code 0) if everything is clean or the file isn't a manifest
11+
3. **Queries the Socket.dev API** to check for malware
12+
4. **Blocks the edit** (exit code 2) if malware is detected
13+
5. **Allows** (exit code 0) if everything is clean or the file isn't a manifest
1514

1615
## How it works
1716

@@ -30,11 +29,8 @@ Build Package URLs (PURLs) for each dep
3029
3130
3231
Call sdk.checkMalware(components)
33-
- ≤5 deps: parallel firewall API (fast, full data)
34-
- >5 deps: batch PURL API (efficient)
3532
36-
├── Malware/critical alert → EXIT 2 (blocked)
37-
├── Low score → warn, EXIT 0 (allowed)
33+
├── Malware detected → EXIT 2 (blocked)
3834
└── Clean → EXIT 0 (allowed)
3935
```
4036

.claude/hooks/check-new-deps/index.mts

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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

2020
import {
2121
parseNpmSpecifier,
@@ -36,8 +36,6 @@ const logger = getDefaultLogger()
3636

3737
// Per-request timeout (ms) to avoid blocking the hook on slow responses.
3838
const 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).
4240
const MAX_BATCH_SIZE = 1024
4341
// How long (ms) to cache a successful API response (5 minutes).
@@ -75,12 +73,9 @@ interface HookInput {
7573
interface 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.
8580
interface 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.
349336
async 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).

.claude/hooks/check-new-deps/package-lock.json

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)