🛡️ HalluciGuard v6.2 — Security & Supply Chain Scanner
Zero External Dependencies • Strictly Read-Only Default • One-Click Windows & IDE Integration • 20-Point SAST & Supply Chain Guard for AI-Generated Code
HalluciGuard is an open-source, single-file static analysis and supply chain security scanner designed to audit Python code produced by AI coding assistants (ChatGPT, Claude, GitHub Copilot, Cursor, etc.) and human developers alike.
It detects hallucinated PyPI packages (Slopsquatting), typosquatted lookalikes, unregistered DNS domains, context-aware hardcoded credentials, LLM prompt injection risks, multi-step taint flow vulnerabilities, and 20 distinct real-world security and hygiene code flaws.
1. Core Architectural Principles
- 100% Standard Library (
stdlib-only): Built exclusively with Python standard libraries (ast,re,pathlib,json,mmap,urllib,concurrent.futures,socket,math,sys,os,time, and platform-guardedwinreg). No third-party packages or virtual environment overhead required. - Strictly Read-Only by Default: Source code files are never modified during scanning. Remediation suggestions are presented as clean, non-intrusive Safe Diff blocks or AI prompt templates. Automated repairs only occur when explicitly instructed via
--patch. - Zero Noise & Context-Aware Secret Detection: Shannon entropy secret scanning evaluates variable identifiers (e.g.,
key,secret,token,password) and excludes UUIDs, CSS color hex codes, and filesystem paths to eliminate false alarms. - AST-Based Parsing (Zero Regex Guesswork): Uses Python's native
ast.NodeVisitorto traverse syntax trees, inspecting actualast.Import,ast.ImportFrom, and callable sinks while ignoring comments and docstrings. - Ultra-Fast Local Caching: Leverages memory-mapped I/O (
mmap), file SHA-256 fingerprinting, and a local 24-hour PyPI metadata cache (~/.halluciguard_cache.json) to deliver sub-second scans.
2. CLI Command Reference
Default Supply Chain Scan
Audits project dependencies across .py files, requirements.txt, and pyproject.toml against the PyPI JSON API:
python halluciguard.py scan .
Comprehensive Deep Scan + Safe Diff Suggestions (--deep --suggest)
Enables all 20 SAST and hygiene checks, domain validation, Shannon entropy secrets, prompt injection analysis, and displays read-only remediation diffs:
python halluciguard.py scan . --deep --suggest
Common CLI Flags
# Scan a single Python file
python halluciguard.py scan app.py --deep --suggest
# Enforce strict exit code (returns 1 if risks are detected; ideal for CI/CD pipelines)
python halluciguard.py scan . --deep --strict
# Output machine-readable JSON for automated toolchains
python halluciguard.py scan . --deep --json
# Generate a standalone Cyber-SOC dark-mode interactive HTML report
python halluciguard.py scan . --deep --report security_report.html
# Apply safe automated AST-validated fixes directly to source files
python halluciguard.py scan . --deep --patch
# Ignore internal private packages or custom libraries
python halluciguard.py scan . --ignore internal_lib,private_sdk
# Initialize starter .guardignore configuration file
python halluciguard.py --init-config
# Clear the local PyPI and SHA-256 file cache
python halluciguard.py clear-cache
3. Module W: 20-Point Security & Code Hygiene Checklist
When invoked with --deep, HalluciGuard evaluates the codebase against the comprehensive Module W security and hygiene benchmark. Common flaws can be automatically repaired via --patch:
| # | Category | Detection Focus | Risk Level | Safe Remediation / Auto-Patch |
|---|---|---|---|---|
| 01 | Deprecated Stdlib | Legacy modules removed or deprecated in Python 3.12+ (imp, cgi, optparse, etc.) |
Warning | Modern stdlib replacements (e.g., importlib, argparse) |
| 02 | Hardcoded Private Key | Hardcoded RSA/EC cryptographic private key blocks (-----BEGIN ... PRIVATE KEY-----) |
Critical | Extract to environment variables or secret manager |
| 03 | Hardcoded DB String | Database connection URIs containing plaintext credentials | Critical | Store in environment variable (e.g., DATABASE_URL) |
| 04 | Hardcoded Cloud Token | Cloud credentials, API keys, or PATs (AWS, GitHub ghp_, Slack, etc.) |
Critical | Move credentials to environment variables |
| 05 | Hardcoded Internal IP | RFC1918 private IPv4 addresses hardcoded directly in application logic | Warning | Dynamic configuration via os.environ.get("SERVICE_HOST") |
| 06 | Web Debug Enabled | Production web applications running with debug=True or DEBUG = True |
Danger | Auto-patchable: DEBUG = False |
| 07 | Insecure CORS | Overly permissive wildcard CORS origins (origins=["*"]) |
Warning | Specify explicit allowed origins list |
| 08 | Insecure Deserialization | Loading untrusted byte streams with pickle.loads(), marshal, or shelve |
Critical | Replace with safe structured formats (json.loads()) |
| 09 | Shell Injection | Invoking system shells via subprocess.run(..., shell=True) |
Critical | Auto-patchable: shell=False with explicit argument list |
| 10 | Insecure Temp File | TOCTOU race conditions via obsolete tempfile.mktemp() |
High | Auto-patchable: tempfile.mkstemp() |
| 11 | Weak Cryptography | Legacy hashing algorithms (hashlib.md5(), hashlib.sha1()) |
High | Auto-patchable: hashlib.sha256() |
| 12 | Insecure YAML Load | Deserializing YAML via yaml.load() without specifying a SafeLoader |
Critical | Auto-patchable: yaml.safe_load() |
| 13 | Weak Randomness | Standard PRNG (random.randint, random.choice) used for tokens or secrets |
Warning | Cryptographically secure secrets.token_hex() |
| 14 | SQL Injection | Dynamic SQL statements formatted via f-strings, %, or string concatenation |
Critical | Use parameterized queries (e.g., cursor.execute(sql, (param,))) |
| 15 | Path Traversal | Dynamic user input concatenated directly into filesystem paths | Critical | Path containment validation via Path.resolve() & is_relative_to() |
| 16 | Disabled SSL | Disabling TLS validation via verify=False or _create_unverified_context |
Critical | Auto-patchable: verify=True |
| 17 | Unvalidated Redirect | Forwarding users to external URLs directly from unvalidated query parameters | Warning | Validate target host against domain allowlist before redirect() |
| 18 | Unsafe Code Pattern | Execution of dynamic code strings via eval() or exec() sinks |
Critical | Replace with safe dispatch dictionaries or ast.literal_eval() |
| 19 | Bare Except | Broad except: clauses catching KeyboardInterrupt and SystemExit |
Warning | Auto-patchable: except Exception: |
| 20 | Global Mutable State | Modifying global state inside asynchronous functions or concurrent coroutines | Warning | Use thread/asyncio locks (threading.Lock) or encapsulated state |
4. One-Click Developer Integrations
Windows Explorer Context Menu (--install-menu)
Registers a user-level Windows Explorer right-click shortcut (HKEY_CURRENT_USER\Software\Classes\Directory\shell\HalluciGuardScan and Directory\Background) without requiring Administrator privileges:
python halluciguard.py --install-menu
Usage:
- Right-click any project folder (or empty workspace area) in Windows Explorer.
- Select "Scan with HalluciGuard".
- A terminal window launches, executes
--deep --suggest, and displays interactive findings.
(Note: On non-Windows operating systems, HalluciGuard provides a clear informative notice.)
VS Code & Cursor Task Configuration (--setup-editor)
Creates or updates .vscode/tasks.json in your project root, safely parsing JSONC comments and assigning the scan to the standard build shortcut (Ctrl+Shift+B):
python halluciguard.py --setup-editor
Usage:
- Open your workspace in VS Code or Cursor.
- Press
Ctrl + Shift + B(or navigate to Terminal → Run Build Task). - HalluciGuard executes within the integrated editor terminal.
5. Model Context Protocol (MCP) Server
HalluciGuard implements the Model Context Protocol (MCP) over standard I/O (JSON-RPC 2.0), enabling AI editors (Cursor, Claude Desktop, Windsurf) to query package safety and scan code snippets dynamically:
python halluciguard.py --mcp-server
Supported MCP Tools:
check_package: Checks package existence on PyPI, verifying age, Slopsquatting, and Levenshtein typosquatting.scan_snippet: Audits in-memory code snippets for insecure AST patterns, prompt injection risks, and supply chain threats.
6. Verification & Testing
HalluciGuard includes a comprehensive test suite covering all modules, regression safeguards, and platform integrations:
python test_halluciguard.py
All 16 unit tests run self-contained using Python's standard unittest library in under one second.
7. License
This project is licensed under the terms of the MIT License.
Metadata
Release files for halluciguard 6.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| halluciguard-6.2.0.tar.gz | 54.9 kB | Without provenance | Details for halluciguard-6.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| halluciguard-6.2.0-py3-none-any.whl | Python 3 | none | any | Details for halluciguard-6.2.0-py3-none-any.whl |
Total release size: 109.5 kB
Release files / halluciguard-6.2.0.tar.gz
| Download URL | halluciguard-6.2.0.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a950520614ede35a536a8901dc7109a6e9d5764ac29d501c410c294c92700529
|
|
BLAKE2b-256 checksum How to use checksums |
5ab1988ab4b9477bf69e2676687d67173ad6091d65412cd133e0aefcdf28e647
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.0
|
Release files / halluciguard-6.2.0-py3-none-any.whl
| Download URL | halluciguard-6.2.0-py3-none-any.whl |
|---|---|
| Size | 54.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a602504dda7f255cf3bff9417e6bc28990b6b998bdf2387db24c0feefee28f0
|
|
BLAKE2b-256 checksum How to use checksums |
d05efa1f75645809e8aea3e809a254dd31071c3e5097105145b51886f6873067
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.0
|
Security for halluciguard 6.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.