APIGuard: Graph-Guided API Authorization & BOLA Detection Engine
"The Vulnerability That Hides in Plain Sight — Made Visible."
⚡ Executive Summary
Broken Object Level Authorization (BOLA / IDOR — OWASP API #1) is the most pervasive and dangerous vulnerability in modern cloud APIs. It does not crash servers, trigger alerts, or return HTTP 500 errors. Instead, it quietly returns HTTP 200 OK, leaking sensitive tenant data to unauthorized actors.
Most DAST scanners test endpoints in isolation: they fuzz parameters, receive 401 Unauthorized or 404 Not Found, and mistakenly declare the API secure.
APIGuard replaces isolated fuzzing with a Resource Dependency Directed Acyclic Graph (DAG):
- Schema & DAG Ingestion: Ingests standard OpenAPI 3.x specifications without custom invented keys, mapping relationships between producer and consumer operations (
POST /projectscreates{project_id}$\to$ consumed byGET /projects/{project_id}). - Dynamic Multi-Identity State Harvest: Automatically authenticates as User A (Owner) to create genuine state and harvest live resource IDs.
- Graph-Guided Policy Inference & Propagation: Observes authorization enforcement on parent endpoints and propagates candidate ownership policies along DAG edges to adjacent/nested endpoints (e.g.,
GET /projects/{project_id}/export). - Differential Payload Verification: Probes the endpoint using User B's (Attacker's) credentials. Rather than blindly trusting status codes, it performs differential analysis on response bodies, confirming BOLA only when private owner-linked fields are leaked.
- AI-Driven Surgical Remediation: Bridges detection to remediation with context-infused prompting. Shows side-by-side comparisons of naive prompts ($v_1$) vs graph-guided prompts ($v_2$), generating draft FastAPI patches and pytest tests for a developer to review.
- Executive Audit Report Export: Instantly exports comprehensive security assessment reports in GitHub-Flavored Markdown (
.md) or printable HTML (save as PDF from the browser print dialog), detailing affected routes, leaked tenant attributes, and cURL repro commands.
🌐 Live Hosted Demo
👉 Launch APIGuard Live Demo (GitHub Pages)
Try APIGuard directly in your browser with zero installation:
- ⚡ Interactive Dependency DAG: Explore operation and resource dependencies with Dagre auto-layout.
- 🎯 Real-Time Audit Replay: Click "RUN EXECUTION AUDIT" to watch live SSE event propagation and node transitions.
- 🔍 Differential Inspector: Inspect leaked victim attributes side-by-side with reproduction cURL commands.
- 📄 Executive Audit Report Export: Download formatted Markdown (
.md) or printable HTML pentest reports. - 📊 Empirical Benchmark Panel: Review measured recall, precision, and ablation comparison tables.
Note: The hosted demo replays genuine engine runs captured by
scripts/record_demo.py. Custom OpenAPI schema ingestion and live model calls require running the backend locally (see Setup & Quick Start below).
📸 Demo Screenshots (Real Captured Execution)
| Screen | Description |
|---|---|
| React Flow DAG: Operation and Identifier nodes with Dagre auto-layout, under the pixel-art banner. | |
| Dry-Run Mode: Planned multi-identity sequence table without sending any traffic. | |
| Real-Time Audit: Streaming console, live SSE event propagation, and red BOLA badge. | |
| Differential Inspector: Aman vs Taaran response diff, leaked fields in red, and repro cURL. | |
| Benchmark & Ablations: 100% recall vs 0% baseline on Defect B, with ablation proofs. | |
| AI Remediation Engine: Side-by-side $v_1$ vs $v_2$ prompt iteration and pytest test suite. | |
| Automated Fix Verification: After reference patch is applied, re-scan proves 0 confirmed leaks and green nodes. |
📊 Measured Benchmark Results
Every metric below was measured by running both scanners against the bundled demo target API (http://127.0.0.1:8000/target); requests are delivered in-process, and the integration tests run the same scanners over real sockets. Ground truth is loaded from benchmarks/manifests/*.json (never accessed by scanners during execution). The numbers come straight from benchmarks/results.json.
| Test Variant | Target Description | Ground Truth | Baseline Recall | Baseline Reqs | APIGuard Recall | APIGuard Reqs | Avg ms / finding |
|---|---|---|---|---|---|---|---|
| Variant A | Direct BOLA on primary route (GET /projects/{id}) |
1 | 100% (1/1) | 7 | 100% (1/1) | 15 | 8.3 ms |
| Variant B | Indirect BOLA on export (GET /projects/{id}/export) |
1 | 0% (0/1) | 7 | 100% (1/1) | 15 | 6.5 ms |
| Variant C | Mutation BOLA on update (PATCH /projects/{id}) |
1 | 100% (1/1) | 7 | 100% (1/1) | 15 | 11.8 ms |
| Variant All | Compound multi-defect scenario (A + B + C) | 3 | 67% (2/3) | 7 | 100% (3/3) | 19 | 5.4 ms |
| Variant Secure | Fully patched target + verifier traps | 0 | n/a (0 FP) | 7 | n/a (0 FP) | 13 | n/a |
🔬 Controlled Ablation Study
- Graph Scanner with Propagation OFF: the scanner stops after the main read route and never tests the nested routes, so it misses the indirect defect (0 of 1, 6 requests).
- Oracle Baseline (Hand-Tagged Rules on Every Route): Matches APIGuard at 100% recall (9 requests vs 15), but requires a human to write a security rule for every route in advance.
How to read these numbers
- The target and the answer key are ours, so this shows the method works on a controlled case, not real-world accuracy.
- APIGuard sends more requests than the rules-only baseline (15 vs 7 on single-defect variants) because it also tests the nested routes. It finds more; it is not cheaper.
- The baseline only tests routes it was given a rule for. There is no brute-force "test every route with two users" baseline yet.
- "Avg ms / finding" is total scan time divided by findings, not time to the first finding.
🛠️ System Architecture & Technology Stack
┌──────────────────────────────────────────────┐
│ React Flow + Vite UI │
│ (Dagre DAG, Live SSE Console, Diff View) │
└──────────────────────┬───────────────────────┘
│ REST / SSE Stream
▼
┌──────────────────────────────────────────────────────────────────────────────────┐
│ APIGuard Backend Engine │
│ │
│ ┌─────────────────────┐ ┌─────────────────────┐ ┌──────────────────────┐ │
│ │ OpenAPI Parser ├──►│ Resource Graph DAG ├──►│ Policy & Confidence │ │
│ │ (openapi-validator) │ │ (Nodes, Typed Edges)│ │ (Heuristic Scoring) │ │
│ └─────────────────────┘ └──────────┬──────────┘ └──────────▲───────────┘ │
│ │ │ │
│ ▼ │ │
│ ┌─────────────────────┐ ┌─────────────────────┐ ┌──────────┴───────────┐ │
│ │ Safe HTTP Executor │◄──┤ TestPlanner │◄──┤ Inference Engine │ │
│ │ (Budget, Allowlist) │ │ (Setup/Ctrl/Probe) │ │ (DAG Rule Propagate) │ │
│ └──────────┬──────────┘ └─────────────────────┘ └──────────────────────┘ │
│ │ HTTP calls │
└──────────────┼───────────────────────────────────────────────────────────────────┘
▼
┌──────────────────────────────────────────────────────────────────────────────────┐
│ Vulnerable Multi-Tenant Target API │
│ (Seed data, Trap endpoints, /auth/login) │
└──────────────────────────────────────────────────────────────────────────────────┘
Technologies Used
- Backend: Python 3.12, FastAPI, Pydantic v2,
aiosqlite(WAL-mode SQLite),openapi-spec-validator,httpx(async ASGI/HTTP client),pytest,pytest-asyncio. - Frontend: React 19, Vite, TypeScript, Tailwind CSS v4 (custom light pixel theme),
@xyflow/react(React Flow),dagre(graph layout),lucide-react, with the Press Start 2P and VT323 pixel fonts. - AI Remediation: LLM via OpenRouter or Gemini (whichever is configured), with SQLite caching and automatic deterministic offline template fallback.
Reused Open-Source Components & Attributions
@xyflow/react&dagre: Interactive node-edge visualization and hierarchical DAG layout.openapi-spec-validator: Strict schema validation against official OpenAPI 3.0/3.1 specs.aiosqlite: Async persistence for scans, real-time events, and deduplicated findings.
⚖️ Safety & Architectural Guarantees
| Category | Status | Details |
|---|---|---|
| Real Engine Execution | Real | Real HTTP requests handled by the real target application. The dashboard and benchmark deliver them in-process (ASGI); the integration tests and CLI use real network sockets. No timer-based mocks or hardcoded node arrays. |
| Deterministic Scanner | 100% Real | The scanner engine makes no LLM calls. Graph traversal, policy evaluation, and differential verification are completely deterministic. |
| AI Remediation Engine | Supported / Offline Fallback | LLM via OpenRouter or Gemini (whichever is configured) is used strictly for post-scan surgical remediation ($v_1 \to v_2$). If no API key is provided, a deterministic offline template is badged. |
| Safe by Default | Working | Requests are strictly restricted to allowlisted loopback hosts (127.0.0.1). Mutating requests (PATCH/DELETE) are blocked unless explicitly toggled. Each scan still creates one test record on the target (the setup step). |
| Git Commit History | Verified | Clean, incremental commit history with tests passing at every stage. |
🎨 Design: Paper & Grace
The dashboard uses a light pixel theme: cream paper with a faint grid, chunky black pixel type with a lime shadow, and gold and moss accents. All the scenery (ruins, a resting knight, a golden tree, a thin golden ring) lives in the banner at the top, so the working panels stay plain and easy to read. The chevron in the toolbar hides the banner to give the panels more room (the choice is remembered; the banner starts open).
Scrolling down turns the banner into the logo: the scenery fades, and the big pixel title shrinks and glides into the toolbar's top-left corner while the buttons slide over to make room (on screens at least 1240px wide; narrower ones just scroll the banner away). Scrolling back up reverses it, and clicking the logo returns to the top. For visitors who prefer reduced motion the logo simply fades in.
The banner is alive: mist drifts over the ruins and water, the floating islands bob, motes of light rise from the spires, golden leaves fall from the tree, birds circle the ruins, arch lights flicker, and the ring quickens while an audit runs. None of it animates when the visitor prefers reduced motion, and the light and birds pause while the banner is off screen.
- The wordmark is an SVG drawn from code, with moss, vines (that sway) and flowers:
PixelTitle.tsx, built frompixelTitleData.ts. - The title-to-logo scroll effect is
BrandDock.tsx: scroll progress goes into CSS variables, nothing re-renders while scrolling. - The scenery is cut from fine pixel art, not redrawn:
pip install -r scripts/requirements.txt, thenpython scripts/make_hero_art.py --src <reference-banner>rebuildsfrontend/src/assets/hero/(add--preview DIRto check the result on the paper colour). The reference image is not stored in the repo. - The light, leaves and birds are drawn on a canvas by
heroLights.ts; where things sit is inheroScene.ts. - The page scrolls over the graph and the report: the graph zooms with Ctrl + scroll (or the +/- buttons), and the report grows instead of scrolling inside itself.
- Colours are Tailwind tokens re-mapped in
index.css, so existing utility classes keep their meaning on the light background.
📁 Codebase Architecture & Key Files
APIGuard/
├── backend/
│ ├── apiguard/ # Python package (pip install apiguard-cli)
│ │ ├── main.py # FastAPI server, REST routes & SSE live scan stream
│ │ ├── db.py # Async SQLite persistence (WAL mode)
│ │ ├── engine/ # Core scanner & security analysis engine
│ │ │ ├── spec.py # OpenAPI 3.x schema ingestion & parameter mapping
│ │ │ ├── graph.py # Resource Dependency DAG builder (nodes & typed edges)
│ │ │ ├── auth.py # Dynamic multi-identity token & session management
│ │ │ ├── planner.py # Test sequence planner (Setup -> Control -> Probe)
│ │ │ ├── executor.py # Safe HTTP executor (budget caps, localhost allowlist)
│ │ │ ├── inference.py # DAG policy inference & propagation engine
│ │ │ ├── verifier.py # Differential payload comparison (BOLA confirmation)
│ │ │ ├── remediation.py # AI surgical patch generator (v1 vs v2 context)
│ │ │ └── models.py # Pydantic v2 data models & schemas
│ │ └── target/ # Sandbox multi-tenant API (Variants A, B, C, Secure)
│ ├── tests/ # Test suite (22 unit & integration tests)
│ └── requirements.txt # Backend dependencies
├── frontend/ # React 19 + TypeScript + Vite + Tailwind CSS v4
│ ├── src/
│ │ ├── components/ # HeroBanner, PixelTitle, GraphView, AuditReportModal, FindingDetail, Modals
│ │ ├── hooks/ # useGraph, useScan (real-time SSE streaming)
│ │ ├── demo/ # Demo-mode client + recorded fixtures (hosted replay)
│ │ ├── assets/hero/ # Pixel-art scenery, floating islands, mist and water for the banner
│ │ └── App.tsx # Main security dashboard
│ ├── package.json
│ └── vite.config.ts
├── benchmarks/ # Ground truth manifests and empirical benchmark data
├── docs/ # Architectural docs, screenshots, and demo script
├── scripts/ # record_demo.py (hosted demo data), make_hero_art.py (banner art)
├── .github/workflows/pages.yml # Deploys the hosted replay demo to GitHub Pages
└── start.bat # Alternative startup runner
🚀 Setup & Quick Start
1. Clone the Repository
git clone https://github.com/Code-Breaker-Ctrl/APIGuard.git
cd APIGuard
2. Quick Launch (Windows)
Double-click:
start.bat
This starts both the FastAPI backend (http://127.0.0.1:8000) and the Vite dashboard (http://127.0.0.1:5173) and automatically opens your default browser.
3. Manual Launch
1. Backend
cd backend
python -m venv .venv
# Windows: .venv\Scripts\activate | Unix: source .venv/bin/activate
pip install -r requirements.txt
python -m uvicorn apiguard.main:app --host 127.0.0.1 --port 8000 --reload
Run backend tests:
pytest backend/tests/ -v
2. Frontend
cd frontend
npm install
npm run dev
Open http://127.0.0.1:5173 in your browser.
3. Command line (optional)
pip install -e . # from the repo root; installs the apiguard command
apiguard scan --dry-run # print the plan, send nothing
apiguard scan # run the scan (add --mutations for PATCH/DELETE)
🗺️ Roadmap (Future Scope)
Planned, not shipped. Full detail in docs/ROADMAP.md.
- Make it real: analyze a GitHub repository from its link, configurable target, auth profiles (Bearer, API key, OAuth2), body-based and compound identifiers, spec-less discovery from HAR captures.
- Detect more: BFLA (API5), mass assignment / BOPLA (API3), safe cross-tenant write and delete checks, ID guessability scoring.
- Smarter graph reasoning: per-edge probabilistic propagation, a request-budget optimiser, a brute-force baseline, randomised benchmark targets.
- Developer workflow: CI/CD gate, SARIF export, regression guard, a verified auto-fix loop and a pull-request bot.
- Platform: workspaces and scan history, redacted evidence vault, compliance mapping, plugin SDK.
⚠️ Known Limitations
- Demo target only: the scanner is wired to the bundled demo API. The target URL, login flow, resource name (
Project), owner field (owner_id) and create-request body are fixed. Importing another OpenAPI file changes which operations are listed, but scans still run against the demo target. Making the target configurable is the next milestone. The demo target keeps its data in memory. - Identifier scope: the prototype extracts runtime resource identifiers primarily from path parameters (
{project_id}); nested body-based compound keys are planned for upcoming releases. - Propagation scope: once the main read route is seen to be owner-only, every other operation that takes an ID is tested. Propagated rules attach a hypothesis and confidence to each result; they do not yet narrow the set of routes tested.
- Safe mutation gate: mutating HTTP verbs are turned off by default to protect target data integrity. The setup step still creates one test record per scan and leaves it behind.
- Dry run is a preview: it lists a setup, control and probe step per route. The live scan reuses one created record, so it sends fewer requests.
- Benchmark scope: measured on our own target with our own answer key, against a baseline that only tests routes it has a rule for.
- Hosted demo is a replay: the GitHub Pages build replays recorded runs; importing a spec and calling a live model need the local backend.
Metadata
Release files for apiguard-cli 0.1.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 |
|---|---|---|---|---|
| apiguard_cli-0.1.0.tar.gz | 53.9 kB | Without provenance | Details for apiguard_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apiguard_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for apiguard_cli-0.1.0-py3-none-any.whl |
Total release size: 108.4 kB
Release files / apiguard_cli-0.1.0.tar.gz
| Download URL | apiguard_cli-0.1.0.tar.gz |
|---|---|
| Size | 53.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
431d01e2ac7f9672b9106736e7fee652268475482d208f94318a2119b26b66a1
|
|
BLAKE2b-256 checksum How to use checksums |
47b31c1fc23eb688c6b4309e4e2255ceb78cf548e779a8352597aca1448f010c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / apiguard_cli-0.1.0-py3-none-any.whl
| Download URL | apiguard_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 54.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6778d4e9f9ace81bc982af90c6a7fdb2a889611ff83d22485651f4bd3a09d65
|
|
BLAKE2b-256 checksum How to use checksums |
b08ebbfb9dec795d522f69566d14f887f05922695fe7d1c499e6aee9fd0028fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for apiguard-cli 0.1.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.