Creating WAF Custom Rules¶
This guide shows you how to create and manage custom Web Application Firewall (WAF) rules through the Peakhour dashboard to protect your applications against specific threats and vulnerabilities.
Before you begin: Understand WAF concepts and have admin access to your Peakhour dashboard.
Understanding WAF Custom Rules¶
WAF custom rules allow you to create targeted security policies that go beyond standard OWASP rule sets. These rules can detect application-specific attack patterns, implement custom logic, and provide granular control over threat detection.
Rule Components¶
Rule Structure:
- Name: Descriptive identifier for the rule
- Description: Detailed explanation of the rule's purpose
- Conditions: Logic that determines when the rule triggers
- Action: What happens when conditions are met (block, allow, log)
- Severity: Impact level (CRITICAL, ERROR, WARNING, NOTICE)
- Tags: Labels for categorization and filtering
Variable Types:
- Request Variables: Headers, body, URI, method, cookies
- Response Variables: Status codes, headers, content
- Session Variables: User sessions, authentication state
- Custom Variables: Application-specific data points
Access WAF Custom Rules¶
Navigate to WAF Management¶
- Log into Peakhour Dashboard
- Select Your Domain from the domain list
- Go to Security → Web Application Firewall
- Click Custom Rules Tab in the WAF interface
Review Existing Rules¶
Before creating new rules, examine current custom rules:
- Active Rules: Currently enforcing security policies
- Disabled Rules: Created but not currently active
- Rule Categories: Organized by attack type or application area
- Performance Impact: CPU and memory usage metrics
Create Basic Custom Rules¶
Create SQL Injection Protection Rule¶
SQL Injection Protection Rule Configuration
Scenario: Protect against advanced SQL injection attempts in form submissions
- Click "Create Custom Rule"
-
Configure Basic Information:
-
Name:
Advanced SQL Injection Detection
-
Description:
Detect sophisticated SQL injection patterns in form data
-
Severity:
CRITICAL
-
Tags:
sql-injection
,forms
,database
-
Set Up Detection Logic:
-
Configure Action:
-
Action Type:
BLOCK
-
Block Message:
Request blocked due to suspicious content
-
Log Level:
ERROR
-
Set Conditions (Optional):
-
Apply to paths:
/contact
,/login
,/register
- Exclude IPs: Add trusted admin IPs if needed
Create XSS Protection Rule¶
XSS Protection Rule Configuration
Scenario: Block cross-site scripting attempts in user input
-
Create New Rule:
-
Name:
XSS Attack Prevention
-
Description:
Block script injection attempts in user inputs
-
Severity:
CRITICAL
-
Tags:
xss
,scripting
,input-validation
-
Configure Detection:
-
Set Response Action:
-
Action:
BLOCK
-
Custom Response Code:
403
-
Response Body: Custom security warning page
Create Rate Limiting Rule¶
Rate Limiting Rule Configuration
Scenario: Prevent automated attacks through request frequency limits
-
Configure Rule:
-
Name:
API Abuse Prevention
-
Description:
Limit API requests to prevent automated attacks
-
Severity:
WARNING
-
Tags:
rate-limiting
,api
,abuse
-
Set Rate Conditions:
-
Configure Actions:
-
Threshold Action:
RATE_LIMIT
(return 429 status) -
Exceeded Action:
BLOCK
(temporary IP block) -
Duration: 5 minutes
Advanced Rule Configuration¶
Multi-Condition Rules¶
Complex Multi-Condition Rule Configuration
Scenario: Create complex rules with multiple conditions
-
Create Combined Logic Rule:
-
Name:
Suspicious Admin Access
-
Description:
Detect unusual admin panel access patterns
-
Set Multiple Conditions:
-
Configure Response:
-
Action:
CHALLENGE
(CAPTCHA verification) - Fallback Action:
BLOCK
if challenge fails
Custom Variable Rules¶
Scenario: Use application-specific variables for detection
-
Create Application-Specific Rule:
-
Name:
Invalid Session Token Access
-
Description:
Detect attempts to use invalid or expired session tokens
-
Configure Custom Variables:
-
Set Actions:
-
Primary Action:
LOG
(record attempt) - Secondary Action:
REDIRECT
to login page
Content Type Specific Rules¶
Scenario: Apply rules based on request content type
-
Create File Upload Rule:
-
Name:
Malicious File Upload Prevention
-
Description:
Block uploads of potentially dangerous file types
-
Configure Content Detection:
-
Set Response:
-
Action:
BLOCK
- Custom Message:
File type not allowed for security reasons
Rule Testing and Validation¶
Test Mode Configuration¶
Before deploying custom rules to production:
-
Enable Test Mode:
-
Toggle "Test Mode" for new rules
-
Monitor for 24-48 hours to observe behavior
-
Review logs for false positives
-
Analyze Test Results:
-
True Positives: Legitimate threats blocked
-
False Positives: Valid requests incorrectly flagged
-
Performance Impact: Response time changes
Rule Refinement¶
Based on test results:
-
Adjust Sensitivity:
-
Tighten conditions if too many false positives
-
Broaden detection if missing threats
-
Modify thresholds for rate limiting rules
-
Whitelist Management:
-
Add trusted IPs to bypass certain rules
-
Create exception paths for legitimate use cases
-
Configure user agent exclusions for known good bots
Staged Deployment¶
Deploy rules gradually:
- Development Environment → Test basic functionality
- Staging Environment → Validate with realistic traffic
- Production (Monitor Mode) → Log only, don't block
- Production (Active Mode) → Full enforcement
Rule Management and Monitoring¶
Performance Monitoring¶
Track rule effectiveness through the dashboard:
Security Metrics:
- Threats Detected: Number of malicious requests identified
- Attacks Blocked: Successfully prevented security incidents
- False Positive Rate: Legitimate requests incorrectly flagged
Performance Metrics:
- Rule Processing Time: Latency added by rule evaluation
- Memory Usage: Resources consumed by rule engine
- Cache Hit Rate: Efficiency of rule result caching
Rule Maintenance¶
Regular maintenance tasks:
Weekly Review:
- Analyze rule effectiveness through security reports
- Check for new attack patterns requiring rule updates
- Review false positive reports from users
Monthly Updates:
- Update regex patterns based on emerging threats
- Optimize rule performance by refining conditions
- Archive unused rules to reduce processing overhead
Quarterly Assessment:
- Comprehensive security audit of all custom rules
- Benchmark against industry standards and threat intelligence
- Plan rule architecture improvements for next quarter
Incident Response Integration¶
Connect custom rules to incident response:
-
Automated Alerting:
-
Critical rule triggers → Immediate notification
-
Pattern detection → Security team escalation
-
Threshold breaches → Management alerts
-
Response Actions:
-
Automatic IP blocking for severe threats
-
Traffic diversion to security checkpoint
-
Evidence collection for forensic analysis
Advanced Use Cases¶
API Security Rules¶
Scenario: Protect REST APIs from abuse and attacks
Rule Name: API Authentication Bypass Detection
Conditions:
- URI starts with /api/v1/
- Missing Authorization header OR invalid JWT format
- NOT in trusted service IP range
Action: Block with 401 Unauthorized
E-commerce Protection¶
Scenario: Protect online store from fraud and abuse
Rule Name: Checkout Fraud Prevention
Conditions:
- URI contains /checkout OR /payment
- More than 5 failed attempts in 10 minutes
- Credit card pattern in unexpected fields
Action: Challenge with additional verification
Content Management Security¶
Scenario: Protect CMS admin areas from attacks
Rule Name: CMS Admin Protection
Conditions:
- URI contains /wp-admin OR /admin OR /cms
- Failed login attempts > 3 in 5 minutes
- User agent contains automated tools signatures
Action: Temporary IP block (15 minutes)
Best Practices¶
Rule Design¶
- Start broad, then narrow - Begin with general detection, refine based on results
- Use descriptive names - Make rule purpose clear for team members
- Document business logic - Explain why each rule exists
- Version control - Track rule changes and rationale
Performance Optimization¶
- Order rules by frequency - Most commonly triggered rules first
- Use efficient operators - Prefer simple string matching over complex regex
- Implement caching - Cache rule results for repeated patterns
- Monitor resource usage - Ensure rules don't impact site performance
Security Considerations¶
- Regular updates - Keep rules current with threat landscape
- Least privilege - Only block what's necessary
- Backup rules - Have alternative detection methods
- Incident logging - Maintain detailed security event logs
This comprehensive approach to WAF custom rules provides robust protection while maintaining flexibility and performance for your web applications.