How sonic-12/api-sentinel works
Purpose and System Shape
API-Sentinel is a runtime API-security system for detecting BOLA, BFLA, enumeration, rate abuse, PII exposure, and undocumented (“shadow”) APIs without application middleware. It captures HTTP traffic through kernel eBPF, processes it in Python, exposes security state through FastAPI, and renders it in a React dashboard.
Entry Points and Runtimes
• Target/demo FastAPI application: backend/app/main.py
• Dashboard FastAPI service: backend/dashboard_api/main.py
• Kernel/userspace capture executable: ebpf/api-sentinel-libbpf/src/main.rs
• React/Vite browser entry: frontend/src/main.jsx, with application routing/UI composition in frontend/src/App.jsx
• Material runtimes are Linux eBPF/kernel facilities, Rust with libbpf-rs, Python 3.10+/FastAPI/Uvicorn, and React/Vite.
Kernel Capture and Enforcement Boundary
The lowest layer attaches eBPF probes to observe traffic, sends captured events through a ring buffer, and uses pinned BPF-map state for enforcement decisions. Rust owns program loading, event consumption, and the bridge to userspace; BPF owns kernel-resident packet/request observation and blocking control.
• ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c
• ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.h
• ebpf/api-sentinel-libbpf/src/main.rs
Detection Engine
Captured request data enters the Python parser/detection subsystem. It reconstructs and decodes requests, validates relevant fields, masks sensitive values before dashboard exposure, and runs behavior/security detectors. BOLA detection is a dedicated engine; rate limiting and enforcement integration provide paths for classifying or acting on abusive traffic.
• backend/parser/integration.py
• backend/parser/request_parser.py
• backend/parser/bola_engine.py
• backend/parser/enforcer.py
• backend/parser/masking.py
Discovery Pipeline
Detection-derived or observed request records flow into a separate discovery pipeline that normalizes endpoints, compares observed APIs with known inventory, generates OpenAPI-oriented output, and writes reports. This is the boundary where raw runtime traffic becomes API posture and shadow-API findings.
• backend/discovery/pipeline.py
• backend/discovery/normalizer.py
• backend/discovery/comparator.py
• backend/discovery/openapi_generator.py
• backend/discovery/report_writer.py
Dashboard API and Data Contract
A dedicated FastAPI dashboard API serves the frontend’s aggregate statistics, alerts, logs, discovery results, and related security views. Its data layer is the backend-facing contract; the browser should consume this API rather than parser or discovery internals directly.
• backend/dashboard_api/main.py
• backend/dashboard_api/data.py
• backend/dashboard_api/__init__.py
Frontend Presentation
The React dashboard presents operational and analytical views for alerts, masked logs, discovery posture, OWASP coverage, analytics, and configuration. frontend/src/api.js is the client-side service boundary to the dashboard API; page modules organize feature views.
• frontend/src/api.js
• frontend/src/pages/Dashboard.jsx
• frontend/src/pages/Alerts.jsx
• frontend/src/pages/Discovery.jsx
• frontend/src/pages/MaskedLogs.jsx
Primary Control Flow
Client requests reach the target application while eBPF observes them independently. Kernel events are consumed by Rust and delivered to the Python detection path. Detection outputs may trigger kernel enforcement and feed discovery/reporting. The dashboard API reads the resulting security/discovery data, and the React client displays it. Design-level details and operational sequencing are maintained in Documentation/Architecture.md and PROCEDURE.md.
Main entry points: integration.py Detection Integration · comparator.py Inventory Comparator · api_sentinel.bpf.c eBPF Programs · data.py Dashboard Data Layer
Components 18
Kernel Capture
Traffic observation and enforcement boundary.
- eBPF Programs · Observes requests and applies map-backed blocking decisions.
ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c - libbpf Capture Bridge · Loads BPF, consumes ring-buffer events, and bridges userspace.
ebpf/api-sentinel-libbpf/src/main.rs
Detection Engine
Python request analysis and response controls.
- Request Parser · Reconstructs, decodes, and validates captured requests.
backend/parser/request_parser.py - Sensitive Data Masking · Masks sensitive values before security data is exposed.
backend/parser/masking.py - BOLA Engine · Analyzes object-level authorization behavior.
backend/parser/bola_engine.py - Detection Integration · Coordinates parser inputs and detector outputs.
backend/parser/integration.py - Enforcement Adapter · Classifies abusive traffic and drives enforcement integration.
backend/parser/enforcer.py
API Discovery
Observed traffic becomes API posture findings.
- Discovery Pipeline · Converts observed records into API posture processing.
backend/discovery/pipeline.py - Endpoint Normalizer
backend/discovery/normalizer.py - Inventory Comparator · Identifies undocumented and shadow APIs.
backend/discovery/comparator.py - OpenAPI Generator
backend/discovery/openapi_generator.py - Discovery Reports
backend/discovery/report_writer.py
Dashboard
Security-data API and browser presentation.
- Dashboard API · Backend-facing contract for aggregate security views.
backend/dashboard_api/main.py - Dashboard Data Layer · Supplies statistics, alerts, logs, and discovery results.
backend/dashboard_api/data.py - React Dashboard · Operational views for alerts, logs, and discovery posture.
frontend/src/App.jsx - Dashboard API Client
frontend/src/api.js
Other components
- API Clients
- Target FastAPI App · Protected application traffic source.
backend/app/main.py
Connections 19
- API Clients → Target FastAPI App: HTTP requests
- API Clients → eBPF Programs: traffic observed
- eBPF Programs → libbpf Capture Bridge: ring-buffer events
- libbpf Capture Bridge → Request Parser: captured requests
- Request Parser → Detection Integration: decoded request data
- Detection Integration → BOLA Engine: authorization analysis
- Detection Integration → Sensitive Data Masking: security records
- Detection Integration → Enforcement Adapter: abuse findings
- Enforcement Adapter → eBPF Programs: enforcement decisions
- Detection Integration → Discovery Pipeline: observed records
- Discovery Pipeline → Endpoint Normalizer: observed endpoints
- Endpoint Normalizer → Inventory Comparator: normalized inventory
- Inventory Comparator → OpenAPI Generator: discovered API model
- Inventory Comparator → Discovery Reports: shadow API findings
- Sensitive Data Masking → Dashboard Data Layer: masked logs and alerts
- Discovery Reports → Dashboard Data Layer: discovery results
- Dashboard Data Layer → Dashboard API: security views
- Dashboard API Client → Dashboard API: dashboard requests
- React Dashboard → Dashboard API Client: loads views