Integrating Coraza WAF into Caddy Web Server: Steel Shield Against OWASP Top 10 Attacks
Guide to integrating Coraza WAF into Caddy Web Server to protect applications from OWASP Top 10 threats like SQL Injection, XSS, and path traversal. Includes configuration, testing,...
Integrating Coraza WAF into Caddy Web Server: Steel Shield Against OWASP Top 10 Attacks
In an era of increasingly sophisticated cyberattacks, protecting web applications from common vulnerabilities such as SQL Injection, Cross-Site Scripting (XSS), and Path Traversal is essential. The OWASP Top 10 represents the most prevalent web security risks, and integrating a Web Application Firewall (WAF) like Coraza into Caddy Web Server creates a robust defense layer for your applications.
Introduction to Coraza WAF and Caddy Web Server
Coraza is an open-source WAF built on the ModSecurity framework, offering full compatibility with the OWASP Core Rule Set (CRS). It operates as a middleware, integrating directly into web servers such as Caddy, Nginx, and Apache. Meanwhile, Caddy is a modern, lightweight web server that supports automatic HTTPS and offers strong extensibility through plugins.
Integrating Coraza with Caddy enables you to protect your web applications from OWASP Top 10 threats, including:
- SQL Injection
- Cross-Site Scripting (XSS)
- Path Traversal Attacks
- Remote Code Execution
- CSRF (Cross-Site Request Forgery)
Prerequisites and Installation
Prerequisites:
- System: Linux (Ubuntu/Debian/CentOS)
- Caddy 2.x or newer
- Go 1.16+ (for compiling Coraza)
- Access to server CLI
Step 1: Install Caddy
sudo apt update
sudo apt install -y curl gnupg2
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install -y caddy
Step 2: Install Coraza from Source
git clone https://github.com/corazawaf/coraza.git
cd coraza
go build -o coraza-waf
sudo cp coraza-waf /usr/local/bin/
Configuring Coraza with Caddy
Modify the Caddy configuration file (/etc/caddy/Caddyfile) to integrate Coraza:
example.com {
root * /var/www/html
file_server
# Enable Coraza WAF
waf {
mode "block"
rules "/etc/coraza/rules/crs_*.conf"
}
# Logging
log {
output stdout
format json
}
}
Explanation:
waf: Activates the Coraza WAF.mode "block": Blocks requests that violate rules.rules: Specifies the path to OWASP CRS rule files.
Testing and Verification
Run Caddy to test the configuration:
sudo caddy run --config /etc/caddy/Caddyfile
Access your website and check the logs:
sudo journalctl -u caddy -f
If Coraza is working correctly, you should see log entries such as:
{"level":"info","msg":"WAF blocked request","rule":"942100","ip":"192.168.1.100","path":"/admin","timestamp":"2024-01-01T00:00:00Z"}
Tuning and Optimization
To optimize security:
- Run Coraza in
detectmode initially to log violations without blocking. - Customize rules in
/etc/coraza/rules/to match your application’s behavior. - Test effectiveness using OWASP ZAP or Burp Suite.
Troubleshooting
- Not working: Check Caddy and Coraza logs; verify configuration file syntax.
- False positives: Review CRS rules and adjust
exclusionsas needed. - Performance issues: Optimize rules, use
rule_idsto skip unnecessary ones.
References
- Advanced Network Configuration on VPS with IPv6, Private Network, and Internal Link Security
- Optimizing Infrastructure Security: Blocking 99% Malicious Bots at Kernel Layer with eBPF-based Firewall and Cilium
- Protect Web API Systems from Application DDoS Attacks Using eBPF XDP Technology
Assumptions: The user has basic Linux CLI and web server configuration knowledge. This guide does not include setting up a specific web application.
Related infrastructure & engineering guides: Cloud VPS with L3/L4/L7 Anycast Anti-DDoS
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
