Skip to content

About

Dual-architecture Financial AppSec lab showcasing OWASP API Top 10 vulnerabilities, live PoC exploits, custom SAST rules, and DevSecOps CI/CD gates.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

50 Commits

Folders and files

Repository files navigation

🛡️ FinSec Guardian

Enterprise Application Security & DevSecOps Platform for Modern Fintech

Python 3.11 FastAPI OWASP API Security Docker Compose Semgrep SAST CI/CD Security Gate

A dual-architecture AppSec laboratory comparing vulnerable financial microservices against production-hardened implementations with custom SAST rules, weaponized PoC exploits, and automated audit reporting.

Quickstart • Architecture • Vulnerabilities vs Remediations • Exploit Demos • Custom SAST Rules • DevSecOps CI/CD


📌 Project Overview

FinSec Guardian is a dual-architecture financial security laboratory designed for Application Security Engineers, Penetration Testers, and DevSecOps professionals. It demonstrates real-world OWASP API Security Top 10 (2023) vulnerabilities within banking APIs alongside enterprise-grade remediations:

  1. Vulnerable Core Banking API (:8000): An intentionally vulnerable microservice demonstrating BOLA/IDOR, Mass Assignment, Hardcoded Secrets, and SSRF.
  2. Hardened Core Banking API (:8001): A production-ready microservice enforcing Object-Level Authorization, Pydantic DTO filtering, DNS-layer SSRF egress filters, and secure JWT handling.
  3. AppSec Engine (appsec-engine/): Custom Semgrep SAST rules, Bandit analyzers, and an automated audit report generator.
  4. Automated PoC Exploit Suite (exploits/): Weaponized scripts demonstrating exploitation and proving remediation.
  5. DevSecOps Pipeline (.github/workflows/): GitHub Actions workflow incorporating Gitleaks, Semgrep, Trivy SCA, and Schemathesis DAST fuzzing.

🏛️ Architecture

                                 ┌─────────────────────────────────┐
                                 │      FinSec-Guardian Hub        │
                                 │     http://localhost:8000/      │
                                 └──────────────┬──────────────────┘
                                                │
                 ┌──────────────────────────────┴──────────────────────────────┐
                 ▼                                                             ▼
  ┌──────────────────────────────┐                              ┌──────────────────────────────┐
  │   🚨 Vulnerable API (:8000)   │                              │     🛡️ Secure API (:8001)     │
  ├──────────────────────────────┤                              ├──────────────────────────────┤
  │ ❌ No Object-Level Auth Checks│                              │ ✅ get_current_user Context  │
  │ ❌ Hardcoded JWT Signing Key │                              │ ✅ Dynamic ENV Secret Keys   │
  │ ❌ Unfiltered Model Updates  │                              │ ✅ Strict DTO (extra="forbid")│
  │ ❌ Blind Webhook Egress      │                              │ ✅ DNS & Private IP Filter   │
  └──────────────┬───────────────┘                              └──────────────┬───────────────┘
                 │                                                             │
                 ▼                                                             ▼
  ┌──────────────────────────────┐                              ┌──────────────────────────────┐
  │ 💥 BOLA: Alice Balance Leaked│                              │ 🔒 403 Forbidden Enforced    │
  │ 💥 Mass Assignment: Bob Admin│                              │ 🔒 422 Extra Field Rejected  │
  │ 💥 SSRF: AWS IMDS Accessible │                              │ 🔒 400 SSRF Filter Blocked   │
  └──────────────────────────────┘                              └──────────────────────────────┘

⚖️ Vulnerabilities vs. Remediations

OWASP Category Vulnerable Implementation (app/vulnerable/) Secure Implementation (app/secure/) CVSS v3.1
API1:2023 BOLA / IDOR Direct object access by account_id with zero caller verification. Depends(get_current_user) verifies caller ownership or is_admin. 8.6 (High)
API2:2023 Broken Auth Static string literal "insecure_dev_secret_key_12345" used in jwt.encode. os.getenv("JWT_SECRET_KEY") with algorithm and issuer restrictions. 8.2 (High)
API3:2023 Mass Assignment user.update(update.dict()) allows overwriting is_admin and role. Strict Pydantic DTO with ConfigDict(extra="forbid"). 8.8 (High)
API7:2023 SSRF requests.get(callback_url) blind fetch allows hitting AWS IMDS 169.254.169.254. DNS pre-resolution + IP subnet blocklist (10.0.0.0/8, 169.254.0.0/16, 127.0.0.0/8). 9.8 (Critical)

🚀 Quickstart

Method 1: Running with Docker Compose (Recommended)

Spins up both the Vulnerable API (http://localhost:8000) and the Secure API (http://localhost:8001) simultaneously in isolated containers:

# Build and start all services
docker compose up --build

# Verify running containers
docker compose ps

Method 2: Running Locally (Python Virtual Environment)

# 1. Create and activate virtual environment
python -m venv venv
# Windows:
.\venv\Scripts\activate
# Linux/macOS:
source venv/bin/activate

# 2. Install dependencies
pip install -r app/requirements.txt

# 3. Terminal A: Run Vulnerable API on port 8000
uvicorn app.vulnerable.main:app --host 0.0.0.0 --port 8000 --reload

# 4. Terminal B: Run Secure API on port 8001
uvicorn app.secure.main:app --host 0.0.0.0 --port 8001 --reload

alt text

alt text

alt text

alt text

alt text

alt text

💥 Weaponized PoC Exploits

FinSec Guardian includes standardized CLI PoC exploit scripts under exploits/. You can run them against both the vulnerable and secure APIs to observe real-time security behaviors:

1. Broken Object Level Authorization (BOLA / IDOR)

Bob (User 102) steals Alice's (User 101) balance:

# Against Vulnerable API (Exploit Confirmed)
python exploits/poc_idor.py --url http://localhost:8000

# Against Secure API (Exploit Blocked with 403 Forbidden)
python exploits/poc_idor.py --url http://localhost:8001
[+] Testing BOLA / IDOR against: http://localhost:8000
============================================================
[✓] Authenticated as Bob (User ID: 102)
[*] Sending unauthorized request to read Alice's Account (101)...

[🚨 VULNERABILITY CONFIRMED - BOLA/IDOR DETECTED!]
    Target Account: 101
    Owner Name:     Alice Wonderland
    Balance Leaked: $50,000.00 USD
    Status Code:    200 OK (Expected 403 Forbidden)

alt text

alt text

2. Mass Assignment / Privilege Escalation (BOPLA)

Bob (User 102) injects {"is_admin": true, "role": "admin"} into his profile update:

# Against Vulnerable API (Privilege Escalation Confirmed)
python exploits/poc_mass_assignment.py --url http://localhost:8000

# Against Secure API (Blocked with 422 Unprocessable Entity)
python exploits/poc_mass_assignment.py --url http://localhost:8001
[+] Testing Mass Assignment / BOPLA against: http://localhost:8000
=================================================================
[✓] Authenticated as Bob (User ID: 102 | Initial Role: 'user' | is_admin: False)
[*] Sending PATCH request to escalate privileges...

[🚨 VULNERABILITY CONFIRMED - MASS ASSIGNMENT SUCCESSFUL!]
    Target User ID: 102
    New Role:       admin (Escalated from 'user')
    is_admin Flag:  True (Overwritten!)
    Status Code:    200 OK (Property overwrite allowed)

alt text

alt text

3. Server-Side Request Forgery (SSRF)

Targeting cloud instance metadata (169.254.169.254) through webhook verification:

# Against Vulnerable API (Blind Outbound Request Confirmed)
python exploits/poc_ssrf_metadata.py --url http://localhost:8000

# Against Secure API (Blocked by Egress Filter with 400 Bad Request)
python exploits/poc_ssrf_metadata.py --url http://localhost:8001

alt text

alt text

🔍 Custom Semgrep SAST Rules

Located under appsec-engine/semgrep-rules/:

  1. idor-check.yaml: Identifies endpoints receiving ID path parameters without an authentication dependency (Depends(...)).
  2. no-hardcoded-jwt.yaml: Flags string literals passed directly as JWT secret keys in jwt.encode or jwt.decode.
  3. ssrf-detection.yaml: Flags unvalidated dictionary parameters passed directly into requests.get/post.

Run SAST Scan:

# Direct CLI Runner (Recommended on Windows, macOS, Linux):
python appsec-engine/scan.py

# Or via Docker:
docker run --rm -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config /src/appsec-engine/semgrep-rules/ /src/app/

alt text

📊 AppSec Report Generator

Generate an automated Markdown security assessment report and terminal audit dashboard:

python appsec-engine/report_generator.py

Generated report is saved to: docs/appsec-audit-report.md.


alt text

🔄 DevSecOps Pipeline

The GitHub Actions pipeline (.github/workflows/appsec-pipeline.yml) implements multi-layered security gates:

  1. Secret Detection: gitleaks-action detects committed credentials and private keys.
  2. SAST Scanning: semgrep-action executes custom security rules and generates SARIF alerts.
  3. SCA Dependency Audit: trivy-action scans requirements.txt for known CVEs.
  4. DAST Dynamic Fuzzing: Launches the API and executes schemathesis fuzzing against openapi.json.

👥 User Accounts (In-Memory Ledger)

User ID Username Role Initial Balance Intended Privileges
101 alice user $50,000.00 Standard customer account
102 bob user $150.00 Standard customer account (Used in PoCs)
999 admin admin $1,000,000.00 Security Officer / Administrator

👨‍💻 Author & Motivation

Created by: Mehdi Mejri
This project was developed independently out of curiosity, passion for Application Security (AppSec), and a drive to explore the practical boundaries of modern fintech API defenses, OWASP vulnerabilities, and DevSecOps engineering.


Made with ❤️ by Mejri Mehdi

About

Dual-architecture Financial AppSec lab showcasing OWASP API Top 10 vulnerabilities, live PoC exploits, custom SAST rules, and DevSecOps CI/CD gates.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages