Commit b72da78
authored
Add dependency malware checker hook for Claude Code (#1184)
* feat(hooks): add check-new-deps hook to block malware packages
Intercepts Edit/Write on dependency files across 17+ ecosystems
(npm, PyPI, Cargo, Go, Maven, etc.) and checks new deps against
Socket.dev's malware API before they're added. Uses SDK v4
checkMalware() with batch chunking, namespace-aware matching,
and in-memory caching.
* refactor(tests): use @socketsecurity/lib spawn and whichSync instead of child_process
* fix(hooks): use JSON parser for Pipfile.lock instead of regex extractor
Pipfile.lock is JSON (with "default" and "develop" sections keyed by
package name), not requirements.txt format. The regex-based extractPypi
silently matched zero dependencies. Add a dedicated extractPipfileLock
that parses the JSON structure correctly.
* fix(hooks): use nullish coalescing for new_string/old_string/content
Empty string is a valid value for new_string (Edit that deletes content)
and old_string. Using || instead of ?? caused falsy empty strings to
fall through to the wrong field.
* fix(hooks): add regex fallback for partial Pipfile.lock content
* fix(hooks): strip .git suffix from Swift names, remove spurious brew key
- Swift package URLs commonly end with .git (e.g. vapor.git); strip the
suffix so the PURL lookup finds the correct package
- Remove 'brew' extractor key that matched any path ending in 'brew';
only 'Brewfile' is the correct Homebrew manifest filename
* fix: fix Cargo.toml and npm extractor false positives
- Cargo.toml: Only extract deps from [dependencies] sections, not
metadata like name, version, edition
- npm: Exclude known package.json metadata field names that match
the dep pattern but aren't dependencies1 parent f49df6e commit b72da78
File tree
8 files changed
+1870
-0
lines changed- .claude
- hooks/check-new-deps
- test
8 files changed
+1870
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
0 commit comments