23 - IP Security
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ IP Security Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
Incoming Request
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Security Middleware │
│ (WSGI Layer) │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 1. Get Real IP (check proxy headers) │ │
│ │ CF-Connecting-IP → X-Real-IP → X-Forwarded-For → remote_addr │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 2. Check IP Ban List │ │
│ │ - Is IP in ip_bans table? │ │
│ │ - Is ban expired? │ │
│ │ - Is ban permanent? │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────┴─────────────────────┐ │
│ │ │ │
│ Banned Not Banned │
│ │ │ │
│ ▼ ▼ │
│ Return 403 Continue to App │
│ Forbidden │
└─────────────────────────────────────────────────────────────────────────────┘Detection Mechanisms
1. 404 Error Tracking
2. Invalid API Key Tracking
Configuration
Security Thresholds
Database Schema
ip_bans Table
error_404_tracker Table
IP Resolution
Proxy Header Priority
Security Middleware
WSGI Implementation
Route Decorator
Admin Interface
Security Dashboard
Manual Ban/Unban
Repeat Offender Escalation
Best Practices
Rate Limiting Integration
Whitelisting
Key Files Reference
File
Purpose
Last updated