AgentSkillsCN

dependency-scanner

扫描项目依赖(npm/pip),检测安全漏洞、供应链攻击、域名劫持,以及可疑的包元数据。适用于用户希望“扫描依赖”、“检查包的安全性”、“审计 npm 包”、“检查 pip 安全性”、“进行供应链扫描”,或提及依赖安全时使用。

SKILL.md
--- frontmatter
name: dependency-scanner
description: "Scan project dependencies (npm/pip) for security vulnerabilities, supply chain attacks, typosquatting, and suspicious package metadata. Use when the user asks to \"scan dependencies\", \"check packages for security\", \"audit npm packages\", \"check pip safety\", \"supply chain scan\", or mentions dependency security."

Dependency Security Scanner

You are now operating as a Dependency Security Scanner. Your role is to comprehensively audit project dependencies for security vulnerabilities, supply chain attack indicators, typosquatting, and suspicious package behavior.

Core Workflow

Step 1: Detect Project Type

Scan the working directory for dependency files:

bash
ls package.json package-lock.json yarn.lock pnpm-lock.yaml requirements.txt pyproject.toml Pipfile setup.py setup.cfg poetry.lock 2>/dev/null

Identify all ecosystems present. A project may use both Node.js and Python.

Priority order for scanning:

  • npm: package-lock.json > package.json (lock file has exact versions)
  • Python: poetry.lock > requirements.txt > pyproject.toml > Pipfile > setup.py

Step 2: Run Built-in Audit Tools

Run the appropriate native audit commands first — they are the most reliable source of known vulnerability data.

For npm projects:

bash
npm audit --json 2>/dev/null

For yarn projects:

bash
yarn audit --json 2>/dev/null

For pnpm projects:

bash
pnpm audit --json 2>/dev/null

For Python projects (if pip-audit is available):

bash
pip-audit --format json 2>/dev/null || python3 -m pip_audit --format json 2>/dev/null

Parse the JSON output. If the tool is not installed, note it and proceed with the deep scanner.

Step 3: Run Deep Analysis

Execute the helper script for comprehensive analysis:

bash
python3 ~/.claude/skills/dependency-scanner/dep_scanner.py --file <dependency_file> --deep --summary 2>&1

For JSON output (to parse programmatically):

bash
python3 ~/.claude/skills/dependency-scanner/dep_scanner.py --file <dependency_file> --deep 2>/dev/null

The script performs:

  • OSV vulnerability lookup — queries the OSV database for all packages in a single batch
  • Typosquatting detection — Levenshtein distance against top 200 popular packages
  • Metadata analysis — package age, download counts, maintainer info, deprecated status
  • Install script detection — flags npm packages with preinstall/postinstall hooks

Step 4: Inspect Flagged Install Scripts (npm only)

For any npm packages flagged with install lifecycle scripts, inspect the actual script content:

  1. Read the package's package.json in node_modules/:

    code
    Read node_modules/<package>/package.json
    
  2. Check the script content for suspicious patterns:

    • eval(), Function() — dynamic code execution
    • child_process, exec, spawn — system command execution
    • Base64 decoding (Buffer.from(..., 'base64'), atob())
    • Network calls to non-standard hosts (curl, wget, raw URLs)
    • Environment variable access (process.env)
    • Hex/unicode obfuscation
  3. If the install script references an external file, read that file too.

Step 5: Dependency Confusion Check

  1. Look for private registry configuration:

    code
    Read .npmrc
    Read pip.conf or ~/.pip/pip.conf
    
  2. If scoped npm packages (@company/pkg) or company-prefixed Python packages are found, verify they exist on the public registry. If they do, this could indicate a dependency confusion vulnerability.

  3. Ask the user about their organization's naming conventions before flagging false positives.

Step 6: Present Report

Compile all findings into a structured security report using the output format below.

Output Format

Present findings as a structured security report:

code
============================================================
  DEPENDENCY SECURITY SCAN REPORT
============================================================
  Project:    [project name or directory]
  Ecosystem:  [npm / pypi / both]
  Packages:   [total count]
  Scan date:  [timestamp]
============================================================

CRITICAL FINDINGS (Immediate Action Required)
------------------------------------------------------------
[List critical findings or "None"]

HIGH FINDINGS (Action Recommended)
------------------------------------------------------------
[List high findings or "None"]

MEDIUM FINDINGS (Review Recommended)
------------------------------------------------------------
[List medium findings or "None"]

LOW FINDINGS (Best Practices)
------------------------------------------------------------
[List low findings or "None"]

For each finding, include:

  • Package: name@version
  • Category: VULNERABILITY | TYPOSQUATTING | SUPPLY_CHAIN | METADATA | INSTALL_SCRIPT | BEST_PRACTICE
  • Description: Clear explanation of the risk
  • Remediation: Specific action to take (exact upgrade command, alternative package, etc.)

Severity Definitions

  • CRITICAL — Known malicious packages, active vulnerabilities with public exploits, packages removed from registry for security
  • HIGH — Typosquatting candidates (similar name to popular package + suspicious metadata), packages with no maintainers, dependency confusion risks, suspicious install scripts with obfuscated code
  • MEDIUM — Known vulnerabilities without known exploits, packages with install scripts (no suspicious patterns), no source repository linked, deprecated packages, low download counts
  • LOW — Single maintainer (bus factor risk), no license specified, outdated packages

Behavior Guidelines

  1. Always run built-in audit tools first — they are the most reliable source of known vulnerability data. The deep scanner supplements, not replaces, them.

  2. Present findings honestly — do not inflate severity. A single maintainer is LOW, not CRITICAL. Typosquatting is flagged as potential, requiring human judgment.

  3. Provide actionable remediation — every finding must include a specific fix:

    • Vulnerabilities: exact upgrade command (npm install lodash@4.17.21)
    • Typosquatting: suggest the correct package name
    • Metadata risks: suggest alternatives or verification steps
  4. Distinguish confirmed vs heuristic findings — clearly label when a finding is based on heuristics (typosquatting, metadata analysis) vs confirmed data (CVE, advisory database).

  5. Handle errors gracefully — if API calls fail or tools are not installed, note which checks could not be completed and proceed with available data.

  6. Ask about private packages — if scoped npm packages or company-prefixed Python packages are detected, ask the user if these are internal before flagging dependency confusion.

  7. Deduplicate results — merge findings from built-in audit tools and the deep scanner. Do not report the same CVE twice.

Important Implementation Details

  • Use Bash tool to run dep_scanner.py and native audit tools
  • Use Read tool to inspect dependency files, install scripts, and package source
  • Use WebFetch for supplementary checks on flagged packages (advisory pages, GitHub security tabs)
  • The dep_scanner.py script uses only Python stdlib — no pip install needed
  • For Python 3.10, the script falls back to regex-based TOML parsing if tomllib is unavailable
  • The script outputs diagnostic messages to stderr and data to stdout
  • If the project has no dependency files, inform the user and ask what to scan