Skip to content

feat: SDK v4 malware API + check-new-deps hook#1182

Closed
John-David Dalton (jdalton) wants to merge 24 commits intomainfrom
feat/sdk-v4-malware-api
Closed

feat: SDK v4 malware API + check-new-deps hook#1182
John-David Dalton (jdalton) wants to merge 24 commits intomainfrom
feat/sdk-v4-malware-api

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 9, 2026

Summary

Upgrades @socketsecurity/sdk from 3.4.1 to 4.0.0 and adds a Claude Code pre-tool hook that checks new dependencies against Socket.dev before they're added to the project.

What's new

SDK v4 upgrade

  • Bumps @socketsecurity/sdk to 4.0.0 in workspace catalog
  • v4 adds checkMalware() which handles both single-dep firewall requests and batch PURL API automatically

check-new-deps hook (.claude/hooks/check-new-deps/)

A pre-tool hook that intercepts every Edit/Write to dependency manifest files across 17+ ecosystems (npm, PyPI, Cargo, Go, Maven, Gems, Composer, NuGet, Swift, Dart, Terraform, Homebrew, Conan, Nix, GitHub Actions, and more).

How it works:

  1. Detects manifest file type from the path
  2. Extracts newly-added deps (diff-aware — only checks what's new)
  3. Calls sdk.checkMalware() to check for malware and critical alerts
  4. Blocks the edit (exit 2) if malware found, warns on low scores, allows otherwise

Uses SDK v4's checkMalware() instead of hand-rolled fetch calls — the SDK handles routing (≤5 deps → parallel firewall, >5 → batch API), retries, and policy normalization.

Integration

  • Hook registered in .claude/settings.json (PreToolUse on Edit|Write)
  • Hook is a workspace package using catalog: for all deps (DRY)
  • .gitignore updated to track .claude/hooks/ and .claude/settings.json
  • Security-scan skill cross-references the hook

Documentation

  • Comprehensive README at .claude/hooks/check-new-deps/README.md
  • Includes ecosystem table, flow diagram, exit code reference
  • Written for junior dev accessibility

Test plan

  • pnpm run build:cli passes
  • Hook returns 0 for non-manifest files
  • Hook returns 0 for clean deps
  • Hook returns 2 for known malware packages
  • node --test .claude/hooks/check-new-deps/test/*.test.mts passes

Note

Medium Risk
Introduces a new pre-tool hook that can block Claude Edit/Write operations based on Socket.dev API results, which could affect developer workflows if parsing or API behavior is wrong. Also upgrades @socketsecurity/sdk to 4.0.0, which may have compatibility impact wherever the SDK is consumed.

Overview
Adds a Claude Code PreToolUse hook (.claude/hooks/check-new-deps/) that detects dependency manifest edits across multiple ecosystems, diffs old_string vs new_string to find new dependencies, and queries Socket.dev via sdk.checkMalware() to block malware/critical alerts (exit 2) and warn on low scores (exit 0).

Wires the hook into .claude/settings.json, adds a dedicated workspace package with tests/docs/tsconfig, updates .gitignore to track the new .claude hook/settings files, and bumps @socketsecurity/sdk to 4.0.0 (with corresponding pnpm-workspace.yaml/pnpm-lock.yaml updates).

Reviewed by Cursor Bugbot for commit ca25e24. Configure here.

SDK v4 exposes `checkMalware()` which handles firewall vs batch routing
internally, simplifying consumers that need malware/security checks.
to use SDK v4's checkMalware() method instead of hand-rolled fetch
calls. The SDK handles firewall vs batch routing internally, so we
remove checkSingleDep(), checkBatchDeps(), FIREWALL_API_URL, and the
BatchArtifact interface.
- Add .claude/hooks/* to pnpm workspace packages
- Replace hardcoded versions with catalog: references
- Add package name for workspace resolution
- Register check-new-deps hook in .claude/settings.json
- Allowlist settings.json in .gitignore
- Add comprehensive README with ecosystem table and flow diagram
- Reference the hook from the security-scan skill
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 9, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​anthropic-ai/​claude-code@​2.1.92 ⏵ 2.1.987710086 +110070
Updatednpm/​@​socketsecurity/​sdk@​3.4.1 ⏵ 4.0.0100100100100100

View full report

@socket-security-staging
Copy link
Copy Markdown

socket-security-staging bot commented Apr 9, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​anthropic-ai/​claude-code@​2.1.92 ⏵ 2.1.98100 +110086 +110070
Updatednpm/​@​socketsecurity/​sdk@​3.4.1 ⏵ 4.0.0100100100100100

View full report

Add update.mts script that checks for new zizmor and sfw releases,
respecting the 7-day minimumReleaseAge cooldown for third-party tools
while updating Socket-owned tools immediately.
- SFW shims: read SOCKET_API_KEY from env/.env.local at runtime
  instead of embedding plaintext secret in shim scripts
- check-new-deps: chunk API requests instead of silently dropping
  deps beyond MAX_BATCH_SIZE (1024)
- check-new-deps: include namespace in result matching key to avoid
  collisions (e.g. @types/node vs node)
- check-new-deps: tighten PyPI extractor to require version specifier
  context, preventing over-matching of ordinary Python keywords
- Shim .env parser: strip quotes, inline comments, whitespace, handle
  spaces around = sign
- Fix .env file ordering: .env.local before .env (matches shim runtime)
- Remove hardcoded "7 days" from update.mts; compute from COOLDOWN_MS
…dating skill

- Bump catalog and minimumReleaseAgeExclude to match installed version
- Add phase 3c to updating skill: sync Claude Code version from
  installed binary, bypasses cooldown since we're the ones running it
- Install-time .env parser: handle spaces around =, strip quotes,
  strip inline comments
- extractNpm: filter by version-specifier pattern to avoid false
  positives from scripts/config fields
- Windows: generate .cmd shims alongside bash shims, matching CI
  pattern (strip shim dir from PATH via batch string replacement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant