Skip to main content

PyShield

CI PyPI version License: MIT Python: 3.11+ Managed with uv

PyShield is a developer-focused, open-source static security analysis platform for Python projects, maintained under the ZN-Forge organization.

Its primary purpose is to help developers identify potential security vulnerabilities in their code before reaching production through fast, deterministic AST analysis.


[!NOTE] Current Status: Version 0.1.0 (Core Engine, Injection, Secrets & Cryptography) PyShield v0.1.0 provides a fast, deterministic static analysis engine, rule registry, code execution/injection rules, secret detection, and cryptography security analysis. All detected secrets are automatically masked in output to prevent sensitive data leakage. Future capabilities (SARIF export, dependency scanning, React UI, etc.) are planned for upcoming releases.


Core Philosophy

  1. Deterministic-First: Security detection is powered primarily by deterministic AST analysis and strict rules. Findings are verifiable and reproducible.
  2. Local-First & Privacy-Focused: Source code is analyzed entirely on your local machine and is never transmitted to external services.
  3. Secret Protection by Design: Detected secret values and key material are masked in terminal reports and findings to prevent credential exposure.
  4. Core Decoupling: The static security analysis engine is strictly decoupled from presentation, web server, and persistence layers.
  5. Minimal Dependencies: The core analysis leverages Python's built-in ast standard library to remain fast, lightweight, and maintainable.
  6. Zero False-Positive Focus: Rules are designed conservatively to highlight high-confidence security hazards without flooding developers with noise.

Supported Rules

Execution & Code Injection (Phase 1)

Rule ID Name Severity CWE Description
PS101 Dangerous eval() usage CRITICAL CWE-95 Detects calls to built-in eval(), preventing dynamic code execution risks.
PS102 Dangerous exec() usage CRITICAL CWE-95 Detects calls to built-in exec(), preventing dynamic statement execution vulnerabilities.
PS103 Use of os.system() HIGH CWE-78 Detects calls to os.system() which execute commands via shell strings.
PS104 Unsafe subprocess execution HIGH CWE-78 Detects subprocess execution calls configured with shell=True.

Secret & Key Material Detection (Phase 2)

Rule ID Name Severity CWE Description
PS201 Hardcoded Secret / Credential HIGH CWE-798 Detects hardcoded passwords, tokens, secrets, and API keys with entropy filtering and placeholder exclusion.
PS202 Private Key Material CRITICAL CWE-321 Detects hardcoded RSA, EC, DSA, and OpenSSH private key PEM headers and content.
PS203 High-Confidence API Token HIGH CWE-798 Detects provider-specific tokens (AWS, GitHub classic/fine-grained, Slack, Google, Stripe) using strict patterns.

Cryptographic Analysis (Phase 2)

Rule ID Name Severity CWE Description
PS301 Weak Hash Algorithm MEDIUM CWE-328 Detects insecure MD5 and SHA-1 hashing via hashlib (exempts usedforsecurity=False).
PS302 Insecure Cryptographic Algorithm HIGH CWE-327 Detects broken legacy ciphers (DES, 3DES, Blowfish, ARC4) in cryptography and PyCryptodome.
PS303 Insecure Randomness HIGH CWE-338 Detects use of standard pseudo-random random module in security-sensitive contexts (tokens, salts, keys, auth).

Installation

PyShield can be installed from PyPI using pip or uv:

# Using pip
pip install pyshield-security

# Using uv
uv add pyshield-security

# Or as a global CLI tool using uv:
uv tool install pyshield-security

[!NOTE] The PyPI distribution package name is pyshield-security. The command-line command is pyshield, and the Python import package is pyshield:

pyshield --version
import pyshield

Development Setup

For local development or contributing, clone the repository and synchronize the isolated virtual environment using uv:

Prerequisites

  • Python 3.11 or higher
  • uv package manager

Setup

git clone https://github.com/ZN-Forge/pyshield.git
cd pyshield
uv sync

This creates a project-local .venv/ containing all runtime and development dependencies locked in uv.lock.


CLI Usage

Check Version

# Direct CLI command (if installed via pip or uv tool):
pyshield --version

# Or inside the local development environment:
uv run pyshield --version

Scan Current Directory

uv run pyshield scan .

Scan Specific Directory or File

uv run pyshield scan src/
uv run pyshield scan app/main.py

CLI Options

Usage: pyshield scan [OPTIONS] [PATHS]...

Arguments:
  [PATHS]...                    One or more paths to scan (default: current directory)

Options:
  --fail-on [LOW|MEDIUM|HIGH|CRITICAL]
                                Minimum severity to trigger non-zero exit code [default: LOW]
  -e, --exclude TEXT            Additional glob patterns or directories to exclude
  -d, --disable-rule TEXT       Rule ID to disable (e.g. -d PS101)
  --enable-rule TEXT            Explicit rule ID to run (e.g. --enable-rule PS103)
  --help                        Show help message and exit

Exit Codes

  • 0: Scan completed successfully; no findings at or above configured failure threshold.
  • 1: Security findings detected at or above configured failure threshold.
  • 2: Fatal error (target path not found, or all target files failed parsing).

Development & Quality Gates

PyShield enforces strict quality gates before any code is merged:

# Run tests with coverage
uv run pytest --cov=pyshield --cov-report=term-missing

# Run Ruff linter
uv run ruff check .

# Run Ruff format check
uv run ruff format --check .

# Run strict type checking
uv run mypy src

Planned Architecture (Future Phases)

The following capabilities are deliberately planned for subsequent phases:

  • Phase 1 (Completed): Core static analysis engine, rule registry, injection rules (PS101PS104), CLI, and terminal reporter.
  • Phase 2 (Completed): Secret detection engine (PS201PS203) and Cryptography rules (PS301PS303) with zero leakage protection.
  • Phase 3+: Dependency vulnerability scanning (PS8xx) and Framework-specific rules (Django, FastAPI, Flask).
  • Phase 4+: Standard SARIF, JSON, and Markdown export formats.
  • Phase 5+: Optional Local AI analysis layer (via Ollama / llama.cpp) to explain and contextualize deterministic findings.
  • Phase 6+: Local Web UI (React + TypeScript + Vite + Tailwind CSS) with FastAPI backend and SQLite persistence.
  • Phase 7+: Comprehensive product/documentation website on GitHub Pages and contributor ecosystem.

License

This project is licensed under the MIT License.

Download files

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

Source Distribution

pyshield_security-0.1.0.tar.gz (92.7 kB view details)

Uploaded Source

Built Distribution

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

pyshield_security-0.1.0-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file pyshield_security-0.1.0.tar.gz.

File metadata

  • Download URL: pyshield_security-0.1.0.tar.gz
  • Upload date:
  • Size: 92.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for pyshield_security-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7ad98ff33d2b1192c3674deaf8197a8b8e98ba41cae91d4973b73ab78acf6ae
MD5 8ec68f8b56b2be0ee7a45f7a67226a48
BLAKE2b-256 f9310875e35973a1fad970e25d4f6b5dbf36e301eee5f7e3c66f46c54f7b856f

See more details on using hashes here.

File details

Details for the file pyshield_security-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyshield_security-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a116f9dd75ae32321c5cb562fe1910431c167700e4ac62987967062538d3c2df
MD5 3cadd3a5af92178ee6593b5903cea671
BLAKE2b-256 af91989939160e33fb5307daaba0a8a870f72d708f9894360a1507d52fa091ee

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page