Skip to main content

Reachability-aware dependency vulnerability scanner for Python

Project description

ReachGuard ๐Ÿ›ก๏ธ

Reachability-Aware Dependency Vulnerability Scanner for Python

PyPI Version Python 3.10+ License: MIT OSV.dev PyCG Powered


๐ŸŽฏ The Problem

Traditional dependency security tools (Dependabot, Snyk, Safety) flag hundreds of vulnerabilities simply because a package version is listed in requirements.txt. However, in real-world applications:

  • >80% of flagged CVEs are completely unreachable because your application never imports or calls the vulnerable functions.
  • Developers suffer from severe alert fatigue, leading to critical vulnerabilities being ignored amidst the noise.
  • Enterprise reachability tools are expensive, proprietary, and require sending private code to external cloud SaaS platforms.

โœจ The Solution

ReachGuard is an open-source, local-first, zero-cost vulnerability scanner that performs static call-graph reachability analysis. It traces your application's execution path from entry points down to external dependency calls to verify whether a vulnerable function can actually be reached at runtime.

[ Entry Points ] ---> [ AST Walk ] ---> [ PyCG Call Graph ]
                                               โ”‚
                                               โ–ผ
[ OSV Advisory ] ---> [ Target Mine ] ---> [ BFS Reachability Check ]
                                               โ”‚
                                               โ–ผ
                                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                  โ”‚   REACHABLE   (Action!)  โ”‚
                                  โ”‚   UNKNOWN     (Review)   โ”‚
                                  โ”‚   UNREACHABLE (Ignore)   โ”‚
                                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Key Features

  • ๐ŸŽฏ Smart Reachability Ranking: Classifies findings into:
    • REACHABLE ๐Ÿ”ด: Vulnerable function is reachable from application entry points (High Priority).
    • UNKNOWN ๐ŸŸก: Package is imported but function-level advisory details are sparse (Manual Review).
    • UNREACHABLE ๐ŸŸข: Package contains a CVE, but the vulnerable code path is never called (Safe to Deprioritize).
  • โšก Zero-Cost & Local-First: Built entirely on free, open tools โ€” OSV.dev API (no API key needed) and PyCG (static analysis).
  • ๐Ÿ“ฆ Multi-Format Dependency Support: Auto-detects requirements.txt, pyproject.toml (PEP 621 & Poetry), and Pipfile.lock.
  • ๐Ÿ” AST Entry Point Detector: Automatically identifies if __name__ == '__main__' blocks and web route handlers (@app.route, @app.get, @router.post for Flask, FastAPI, Starlette).
  • ๐Ÿงน Noise & Stdlib Filter: Eliminates false positives by filtering standard library method references (str.format) and template filter names (xmlattr).
  • ๐Ÿ“Š CI/CD Integrated: Rich terminal formatting with severity levels (CRITICAL, HIGH, MEDIUM, LOW), --output-json exports, and --fail-on-reachable exit gates for build pipelines.

โš™๏ธ Installation

Option 1: Via PyPI (Recommended)

Install ReachGuard globally from PyPI:

pip install reachguard

Option 2: From Source

git clone https://github.com/chaitanyabhujbal912006-afk/reachguard.git
cd reachguard
pip install -e .

(Requirements include typer, rich, requests, and pycg)


๐Ÿ’ป Quick Start & Usage

1. Basic Scan (Auto-build Call Graph)

Provide your dependency file and source code directory. ReachGuard will automatically detect entry points and generate the call graph:

python main.py requirements.txt --src ./src

2. Scan using Pre-Built Call Graph

If you already generated a PyCG call graph JSON file:

python main.py requirements.txt --src ./src --call-graph callgraph.json

3. CI/CD Quality Gate Pipeline

Export findings to JSON and break the build if any REACHABLE vulnerabilities exist:

python main.py requirements.txt --src ./src --output-json report.json --fail-on-reachable

๐Ÿ“‹ CLI Reference

Usage: main.py [OPTIONS] REQUIREMENTS_PATH

Arguments:
  REQUIREMENTS_PATH  Path to requirements.txt, pyproject.toml, or Pipfile.lock  [required]

Options:
  -s, --src TEXT          Path to Python source directory for auto call-graph & entry points.
  -g, --call-graph TEXT   Path to pre-built PyCG call graph JSON file.
  -o, --output-json TEXT  File path to export scan findings as structured JSON.
  --fail-on-reachable     Exit with non-zero status (1) if reachable CVEs are detected.
  --help                  Show this message and exit.

๐Ÿ“Š Sample Terminal Output

ReachGuard scanning requirements.txt โ€” 21 pinned dependencies

Loaded call graph: callgraph.json (137 nodes)
Entry points detected: 2

                            ReachGuard Scan Results                            
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Package          โ”‚ CVE / ID            โ”‚ Severity โ”‚ Status       โ”‚ Summary                                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ werkzeug==2.3.3  โ”‚ GHSA-29vq-49wr-vm6x โ”‚ MODERATE โ”‚ REACHABLE    โ”‚ Werkzeug high resource usage parsing... โ”‚
โ”‚ werkzeug==2.3.3  โ”‚ GHSA-87hc-h4r5-73f7 โ”‚ MODERATE โ”‚ REACHABLE    โ”‚ Werkzeug parsing multipart form data... โ”‚
โ”‚ celery==5.2.7    โ”‚ GHSA-1234-abcd-5678 โ”‚ HIGH     โ”‚ UNKNOWN      โ”‚ Celery deserialization advisory         โ”‚
โ”‚ flask==2.3.2     โ”‚ GHSA-68rp-wp8r-4726 โ”‚ LOW      โ”‚ UNREACHABLE  โ”‚ Flask session Vary: Cookie header       โ”‚
โ”‚ jinja2==3.1.2    โ”‚ GHSA-q2x7-8rv6-6q7h โ”‚ MODERATE โ”‚ UNREACHABLE  โ”‚ Jinja sandbox breakout via format       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary:  2 reachable  |  1 unknown  |  2 unreachable  |  0 critical severity (total CVEs: 5)

! Action required: 2 CVE(s) are reachable from your code -- patch or mitigate these first.

๐Ÿ› ๏ธ Architecture & How It Works

                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚   Dependency File Parser      โ”‚
                     โ”‚ (requirements / toml / lock)  โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                     โ”‚
                                     โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚       OSV.dev API Query       โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                     โ”‚
                                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  AST Entry Point Detector    โ”‚    โ”‚  PyCG Static Call Graph      โ”‚
โ”‚  (__main__, @app.route)      โ”‚    โ”‚  (Caller -> Callee Graph)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                                   โ”‚
               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚   Three-Tier BFS Engine       โ”‚
                     โ”‚  1. Basename Match            โ”‚
                     โ”‚  2. Path-Prefix Match         โ”‚
                     โ”‚  3. Top-Level Entry Seed      โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                     โ”‚
                                     โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚     Rich Terminal & JSON      โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1. Dependency Ingestion: Auto-detects dependency files and normalizes package names and exact pinned versions according to PEP 503.
  2. Advisory Resolution: Batch queries OSV.dev REST endpoints to retrieve known vulnerability data and extracts function targets using heuristic regex mining.
  3. Call Graph Generation: Invokes PyCG to construct a complete control-flow call graph of Python callables.
  4. AST Entry Point Mining: Walks repository ASTs to locate execution roots (if __name__ == '__main__', Flask/FastAPI route decorators).
  5. Graph Traversal (BFS): Executes a multi-tier Breadth-First Search from discovered entry points to target vulnerability functions, returning a deterministic ReachabilityStatus.

๐Ÿงช Running Tests

ReachGuard includes a 35-test suite covering AST parsing, OSV target extraction, noise filtering, call-graph normalisation, and reachability traversal:

python tests/test_suite.py

๐Ÿค Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“œ License

Distributed under the MIT License. See LICENSE for details.

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

reachguard-0.1.2.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

reachguard-0.1.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file reachguard-0.1.2.tar.gz.

File metadata

  • Download URL: reachguard-0.1.2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for reachguard-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ba38ab0462401bf9a06024ca34fb18b5c92a0b9faeaaad38e2cec55cd0b16b20
MD5 766101e324e7cc1825b6b1e9160af840
BLAKE2b-256 51d66ab9d8834f6baa2a4b42cabf6e303f0c4926133a16faa1fcef58bd4b596e

See more details on using hashes here.

File details

Details for the file reachguard-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: reachguard-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for reachguard-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a9838c9c30708f6fe36a34ff4a59d7e6ac9022e0ee9ead2d204fa226e03c30a4
MD5 6b47d716fc24cfb9b70ee958188906d9
BLAKE2b-256 c1fd43bd9af64e9419c5d08b6b85bbb1e62961a9f7cf5322373e891ad536fecc

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