Hybrid Web Application Firewall (Hybrid WAF)
Design and implementation of a multi-layer WAF backed by a large language model arbitration layer.
Executive Summary
Web application attacks (SQL injection, XSS, SSRF) routinely bypass traditional signature-based WAFs, while purely behavioral solutions suffer from high false-positive rates. This project addressed both problems with a hybrid architecture: seven graduated filtering layers that cheaply resolve clear cases, plus an LLM-based arbitration layer that decides only the ambiguous cases.
The Problem
- Static rule-based firewalls fail against obfuscated payloads.
- Raising rule sensitivity increases false positives.
- Sending every request to an AI model is prohibitively expensive in latency.
Architecture: Seven Filtering Layers
Layers are ordered by a "cheapest first" principle.
| Layer | Function | Decision Mechanism |
|---|---|---|
| 1 — Protocol validation | HTTP structural integrity | Immediate rejection of malformed requests |
| 2 — Reputation lists | Known-bad IPs and sources | Periodic block/allow lists |
| 3 — Rate limiting | Flood and brute-force suppression | Redis with sliding windows |
| 4 — Signatures | SQLi/XSS/SSRF/Path Traversal patterns | Optimized regex |
| 5 — Semantic analysis | Recursive decoding and normalization | Multi-stage decoding pipeline |
| 6 — Behavioral scoring | Aggregate risk score | Cumulative points system |
| 7 — AI arbitration | Gray-area cases only | Qwen 2.5 / DeepSeek with custom prompt engineering |
AI Arbitration Layer
- Invoked only when the first six layers cannot reach a confident decision.
- Strict prompt engineering forces structured output (allow/block/confidence/attack classification).
- Dual-model cross-check on critical cases.
- Decisions are logged for review and for improving static rules.
Technical Stack
- FastAPI: Async processing as a reverse-proxy middleware.
- Redis: Rate-limit counters and session memory.
- SQLite: Event and decision log.
- Docker: Reproducible packaging.
- Bash: Operations and health-check scripts.
Testing Methodology
- Tested with payloads across OWASP Top 10 categories (obfuscated SQLi, XSS, SSRF).
- Measured false positives before and after enabling the arbitration layer.
- Measured latency impact and the share of requests that reach the AI layer.
Detailed metrics will be published alongside the source code when the project is released publicly.
Lessons Learned
- "Cheapest first" reconciles accuracy with performance.
- Forcing models to emit structured output is a prerequisite for security automation.
- Logging arbitration decisions feeds back into improving static rules.
Related
- DDoS Mitigation System — network-layer defense (2022).