Flask Integration
Complete guide for integrating AIWAF with Flask web applications. AIWAF provides advanced AI-powered security protection through customizable middleware with zero dependencies and flexible storage options.
🤖 AI-Powered Protection
Machine learning anomaly detection that learns from your traffic patterns and adapts to new threats.
🛡️ Multi-Layer Defense
IP blocking, keyword filtering, rate limiting, honeypot timing, and header validation.
🔧 Auto-Configuration
Intelligent directory detection and setup. Commands work from anywhere with zero configuration.
📊 Comprehensive CLI
Complete command-line interface for management, training, and monitoring with verbose output.
💾 Flexible Storage
Choose between database, CSV files, or in-memory storage based on your needs.
⚡ Zero Dependencies
Works without database setup. AI features optional with scikit-learn installation.
🚀 Quick Start
from flask import Flask
from aiwaf_flask import register_aiwaf_middlewares
app = Flask(__name__)
# Basic configuration
app.config.update({
'AIWAF_USE_CSV': True, # Enable CSV storage
'AIWAF_ENABLE_LOGGING': True, # Enable access logging
'AIWAF_DATA_DIR': 'aiwaf_data', # Data directory
'AIWAF_LOG_DIR': 'logs', # Log directory
})
# Register AIWAF protection
register_aiwaf_middlewares(app)
@app.route('/')
def home():
return "Protected by AIWAF!"
📦 Installation & Setup
Get started with AIWAF in your Flask project. Install the package with AI capabilities, configure middleware, and set up protection layers.
View Installation Guide →🔧 Middleware Configuration
Learn how to configure AIWAF middleware in your Flask application. Choose from 7 different protection layers and customize settings for your needs.
View Middleware Guide →⚡ CLI Management
Comprehensive guide to AIWAF Flask CLI commands for training, monitoring, and maintaining your security system with auto-configuration.
View CLI Guide →🛡️ Available Middlewares
| Middleware | Name | Description |
|---|---|---|
| IP & Keyword Block | ip_keyword_block | Blocks malicious IPs and detects attack keywords |
| Rate Limiting | rate_limit | Protects against brute force and DDoS attacks |
| Honeypot Timing | honeypot | Detects automated form submissions |
| Header Validation | header_validation | Validates HTTP headers for security threats |
| AI Anomaly Detection | ai_anomaly | Machine learning-based pattern analysis |
| UUID Tampering | uuid_tamper | Protects against UUID manipulation attacks |
| Request Logging | logging | Comprehensive request/response logging |
🎯 Security Levels
🛡️ Minimal Security
Essential Protection: IP blocking, rate limiting, and logging for small applications and development.
🚀 Standard Security
Recommended: Core protection plus header validation and AI anomaly detection for most production apps.
🔥 Maximum Security
Full Protection: All 7 middlewares enabled for high-security applications and sensitive data handling.
🤖 AI-Focused Security
Modern Protection: Machine learning-based detection with intelligent rate limiting for complex user patterns.
📊 CLI Quick Reference
# Setup and installation pip install aiwaf-flask[ai] python -m aiwaf_flask.cli list all # Management commands python -m aiwaf_flask.cli add blacklist 10.0.0.1 --reason "Malicious" python -m aiwaf_flask.cli train --verbose python -m aiwaf_flask.cli logs --format combined # Monitoring and maintenance python -m aiwaf_flask.cli stats python -m aiwaf_flask.cli model --check python -m aiwaf_flask.cli export --output backup.json
💡 Pro Tip: AIWAF Flask's auto-configuration system ensures commands work from any directory. The CLI automatically detects your data and log directories, making management effortless across different environments.