Skip to main content

Advanced security scanner for detecting AI-generated dependency confusion vulnerabilities with signature verification support

Project description

Dep-Hallucinator

Security scanner that detects AI-generated dependency confusion vulnerabilities in software projects.

Problem

AI code assistants sometimes suggest packages that don't exist. Attackers can register these hallucinated package names with malicious code. When developers install the suggested dependency, they execute the attacker's payload.

Solution

Dep-Hallucinator detects these non-existent packages and suspicious packages that may be malicious registrations.

Features

  • Registry scanning: Checks PyPI, npm, Maven Central, Crates.io, and Go Modules
  • ML detection: Identifies AI-generated naming patterns
  • Heuristic analysis: Analyzes package age, downloads, and metadata
  • Risk classification: CRITICAL/HIGH/MEDIUM/LOW risk levels with explanations
  • Multi-language support: Python, JavaScript, Java, Rust, Go
  • SBOM generation: Creates Software Bill of Materials (SPDX and CycloneDX)
  • CI/CD integration: Exit codes and JSON output

Supported Ecosystems

Language Registry File Types
Python PyPI requirements.txt, poetry.lock, Pipfile.lock
JavaScript npm package.json, yarn.lock
Java Maven Central pom.xml, build.gradle, build.gradle.kts
Rust Crates.io Cargo.toml, Cargo.lock
Go Go Modules go.mod, go.sum

Installation

pip install dep-hallucinator

Usage

# Basic scan
dep-hallucinator scan requirements.txt

# With options
dep-hallucinator scan requirements.txt --rate-limit 5.0 --max-concurrent 10

# JSON output
dep-hallucinator scan requirements.txt --output-format json

# Generate SBOM
dep-hallucinator scan requirements.txt --generate-sbom

# Batch scan
dep-hallucinator batch requirements.txt package.json pom.xml

Example Output

🔍 Scanning 8 dependencies...

📊 Scan Summary           
🚨 CRITICAL │   2   │ VULNERABLE
🔶 HIGH     │   1   │ SUSPICIOUS  
✅ LOW      │   5   │     OK     

🚨 CRITICAL VULNERABILITIES

📦 ai-powered-data-processor (==1.0.0)
   Suspicion Score: 100% (CRITICAL) | ML: 95%
   Reasons:
   • Package does not exist in the registry
   • Vulnerable to dependency confusion attacks
   • ML models indicate high probability of AI generation
   Recommendations:
   → Do not install this package
   → Check if this was generated by an AI assistant

Developer Workflow Integration

For immediate, in-workflow feedback, we recommend integrating dep-hallucinator as a Git pre-commit hook. This provides simple, local security checks before code is committed, helping developers catch issues early.

Git Pre-commit Hook Guide

  1. Ensure dep-hallucinator is installed:

    pip install dep-hallucinator
    
  2. Create a pre-commit script in your project's .git/hooks/pre-commit file (ensure it is executable, chmod +x).

  3. Add the following logic to scan your dependency files and prevent the commit on critical findings:

    #!/bin/bash
    
    # --- dep-hallucinator pre-commit hook ---
    
    # Files to check (adjust as needed for your project)
    DEP_FILES="requirements.txt package.json"
    
    CRITICAL_FOUND=0
    
    for FILE in $DEP_FILES; do
      if [ -f "$FILE" ]; then
        echo "🔍 Scanning $FILE..."
        # Use quiet mode to suppress normal output, and rely on the exit code
        dep-hallucinator scan "$FILE" --quiet
        
        EXIT_CODE=$?
        
        # Exit code 1 indicates Critical vulnerabilities found
        if [ $EXIT_CODE -eq 1 ]; then
          echo "❌ CRITICAL VULNERABILITY FOUND in $FILE. Commit aborted."
          CRITICAL_FOUND=1
        elif [ $EXIT_CODE -ne 0 ]; then
          echo "⚠️  Scan failed or found HIGH risk packages in $FILE. Review before pushing."
        fi
      fi
    done
    
    if [ $CRITICAL_FOUND -eq 1 ]; then
      exit 1  # Abort commit
    else
      exit 0  # Allow commit
    fi
    

Configuration

Create .dep-hallucinator.json:

{
  "scan": {
    "rate_limit": 10.0,
    "max_concurrent": 20,
    "timeout_seconds": 30
  },
  "security": {
    "max_file_size_mb": 10
  }
}

Development

git clone https://github.com/serhanwbahar/dep-hallucinator.git
cd dep-hallucinator
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,test]"
make test

Exit Codes

  • 0: No critical vulnerabilities
  • 1: Critical vulnerabilities found
  • 130: Scan interrupted

Documentation

License

MIT License. See LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dep_hallucinator-1.0.2.tar.gz (105.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dep_hallucinator-1.0.2-py3-none-any.whl (104.2 kB view details)

Uploaded Python 3

File details

Details for the file dep_hallucinator-1.0.2.tar.gz.

File metadata

  • Download URL: dep_hallucinator-1.0.2.tar.gz
  • Upload date:
  • Size: 105.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for dep_hallucinator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4a8eed4260e50ddb98831e399b6f31f883b9074af36e000b0cff13d2d82c85e2
MD5 02b9fe5a80bd21f6236957c910b42932
BLAKE2b-256 7f08d67a8651884aef17a0380453bf5f474b3565d1a3511fe7140c11de5e58db

See more details on using hashes here.

File details

Details for the file dep_hallucinator-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dep_hallucinator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 759d29feb151eeb24ff9ca3ec2fbe0399c4a819520c597082b472a90529f20f2
MD5 80c9279329cfa6abe27ba4a48c46b29a
BLAKE2b-256 d629938ec7e1fea1e54462cfa70c69ba2b0271a410bfe63ce30d56f1b79f32b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page