CodeHero includes optional ModSecurity WAF with OWASP Core Rule Set for protection against common web attacks.
- ModSecurity 3.x - Industry-standard open-source WAF
- OWASP CRS 3.3.5 - ~2,800 rules covering OWASP Top 10
- Automatic Protection - SQL injection, XSS, command injection, path traversal
- Custom Exclusions - Pre-configured for CodeHero functionality
- Go to Dashboard → Packages
- Find "WAF Security Setup" in Configuration Scripts
- Click "Run Setup"
- Wait for installation to complete
sudo /opt/codehero/scripts/setup_waf.sh| Port | Service | Protection |
|---|---|---|
| 9453 | Admin Panel | Full WAF |
| 9867 | Web Projects | Full WAF |
| 9454 | phpMyAdmin | Full WAF |
The WAF blocks these attack types:
| Attack Type | Examples |
|---|---|
| SQL Injection | ' OR '1'='1, UNION SELECT, ; DROP TABLE |
| Cross-Site Scripting (XSS) | <script>alert(1)</script>, javascript: |
| Local File Inclusion | ../../../etc/passwd, file:// |
| Remote File Inclusion | http://evil.com/shell.php |
| Command Injection | ; ls -la, ` |
| Protocol Attacks | HTTP smuggling, header injection |
To prevent false positives, these areas have relaxed or disabled WAF rules:
| Area | Reason |
|---|---|
/socket.io/ |
WebSocket connections |
/terminal |
Shell commands (expected) |
/console |
Claude output (contains code) |
/claude-assistant |
AI responses with code |
/editor/, /save_file |
Code editing |
/api/ |
JSON payloads |
/ticket/, /send_message |
Code snippets in chat |
# Check if ModSecurity is loaded
nginx -t 2>&1 | grep -i modsecurity
# Expected output:
# ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/2784/0)# Test XSS blocking (should return 403)
curl -k -o /dev/null -w "%{http_code}" "https://localhost:9453/?q=<script>alert(1)</script>"
# Test SQL injection blocking (should return 403)
curl -k -o /dev/null -w "%{http_code}" "https://localhost:9453/?id=1' OR '1'='1"WAF blocks are logged to Nginx error logs:
# View recent blocks
sudo tail -f /var/log/nginx/codehero-admin-error.log | grep ModSecurity
# Example log entry:
# ModSecurity: Access denied with code 403 (phase 2).
# Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE'
# [msg "Inbound Anomaly Score Exceeded (Total Score: 18)"]/etc/modsecurity/main.conf
This file includes:
- Base ModSecurity settings
- OWASP CRS rules
- CodeHero custom exclusions
Edit /etc/modsecurity/crs/crs-setup.conf:
# Lower = more strict, Higher = more permissive
# Default is 5 (balanced)
SecAction "id:900110,phase:1,nolog,pass,t:none,setvar:tx.inbound_anomaly_score_threshold=5"Edit /etc/modsecurity/main.conf and add rules like:
# Allow specific parameter
SecRule REQUEST_URI "@contains /my-endpoint" \
"id:1100,phase:1,pass,nolog,ctl:ruleRemoveById=942100"
# Disable WAF for specific path
SecRule REQUEST_URI "@beginsWith /unsafe-but-trusted/" \
"id:1101,phase:1,pass,nolog,ctl:ruleEngine=Off"After changes:
sudo nginx -t && sudo systemctl restart nginxNot recommended for production.
Remove ModSecurity lines from Nginx configs:
# Edit each config
sudo nano /etc/nginx/sites-available/codehero-admin
# Remove these lines:
# modsecurity on;
# modsecurity_rules_file /etc/modsecurity/main.conf;
# Test and restart
sudo nginx -t && sudo systemctl restart nginx-
Check the error log for the rule ID:
sudo tail -20 /var/log/nginx/codehero-admin-error.log | grep ModSecurity -
Find the rule ID (e.g.,
[id "942100"]) -
Add exclusion to
/etc/modsecurity/main.conf:SecRule REQUEST_URI "@contains /my-path" \ "id:1200,phase:1,pass,nolog,ctl:ruleRemoveById=942100" -
Restart Nginx:
sudo nginx -t && sudo systemctl restart nginx
# Check syntax
sudo nginx -t
# Common issues:
# - Missing unicode.mapping file
# - Invalid rule syntax in main.conf
# - Missing CRS files# Verify ModSecurity is enabled
grep -r "modsecurity on" /etc/nginx/sites-available/
# Check SecRuleEngine is On (not DetectionOnly)
grep "SecRuleEngine" /etc/modsecurity/modsecurity.conf# Remove from Nginx configs
sudo sed -i '/modsecurity/d' /etc/nginx/sites-available/codehero-*
# Restart Nginx
sudo systemctl restart nginx
# Optionally remove packages
sudo apt remove libmodsecurity3 libnginx-mod-http-modsecurity- Keep CRS Updated - Check for updates periodically
- Monitor Logs - Review blocked requests for false positives
- Test After Changes - Always verify WAF works after config changes
- Backup Configs - Save working configurations before modifications