Generate WAF Rules for Enhanced Security
Generate layered WAF rules with SQLi match statements, file upload restrictions, threat feed integration, and staged rollout.
Maintainer of this project? Claim this page to edit the listing.
1.0.0Add to Favorites
Why it matters
Automate the creation of robust Web Application Firewall (WAF) rules across multiple platforms like AWS WAF, Cloudflare, and ModSecurity. Protect your web applications from common threats with optimized, low-false-positive security policies.
Outcomes
What it gets done
Generate platform-specific WAF rules (AWS WAF, Cloudflare, ModSecurity).
Implement SQL injection and XSS protection rules.
Configure rate limiting and file upload restrictions.
Optimize rules for performance and minimize false positives.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-waf-rules-generator | bash Overview
WAF Rules Generator
A WAF rule generation skill covering native SQLi detection, rate limiting with trusted-IP exclusion, file-upload restrictions, threat-feed integration, and staged rollout across AWS WAF, Cloudflare, and ModSecurity. Use it when designing a layered WAF rule set that needs native platform detection and a staged, safe rollout.
What it does
This skill generates Web Application Firewall rules across AWS WAF, Cloudflare WAF, ModSecurity, and F5 BIG-IP ASM with an emphasis on layered, performance-optimized protection. It applies condition-based filtering, intelligent rate limiting, geolocation filtering, protocol validation, and content inspection, with rules ordered by frequency and computational complexity. It implements AWS WAF's built-in SqliMatchStatement combined across body and URI fields with text transformations, a rate-based statement scoped down to exclude a trusted IP set, ModSecurity XSS detection tagged to OWASP CRS with anomaly scoring, file upload restriction rules (Lua-based file inspection plus extension blocklisting for dangerous file types), Cloudflare custom rule expressions blocking known scanner user agents (sqlmap, nikto, nessus) and spoofable headers (x-originating-ip, x-forwarded-host), a three-layer protection strategy (protocol/infrastructure, application-specific, behavioral analysis), a threat-intelligence feed integration config (malicious IPs, Tor exit nodes, known-bad domains with hourly updates), and rule management practices (version control, staged log-only rollout before blocking, WAF bypass testing, compliance alignment with PCI DSS/GDPR).
When to use - and when NOT to
Use this skill when designing a layered WAF rule set - using AWS WAF's native SQLi match statement across multiple fields, scoping a rate-based rule to exclude trusted IPs, writing ModSecurity file-upload restriction rules, blocking known scanning tools and spoofable headers in Cloudflare, structuring rules into protocol/application/behavioral layers, integrating external threat-intelligence feeds, or rolling out new rules in log-only mode before enforcing blocks.
It does not cover host-based intrusion detection or endpoint security - it is focused specifically on web application firewall rule design and staged rollout across major platforms.
Inputs and outputs
Inputs are typically the application's attack surface and available threat-intelligence sources. Outputs include platform rules, for example an AWS WAF SQLi rule using the native match statement:
{
"Name": "SQLInjectionRule",
"Statement": {
"OrStatement": {
"Statements": [
{"SqliMatchStatement": {"FieldToMatch": {"Body": {"OversizeHandling": "CONTINUE"}}, "TextTransformations": [{"Priority": 1, "Type": "URL_DECODE"}]}},
{"SqliMatchStatement": {"FieldToMatch": {"UriPath": {}}, "TextTransformations": [{"Priority": 1, "Type": "URL_DECODE"}]}}
]
}
},
"Action": {"Block": {}}
}
Other outputs include a rate-based rule scoped down to exclude a trusted IP set, ModSecurity file-upload restriction rules (Lua scanner plus dangerous extension blocklist), Cloudflare expressions blocking scanner user agents and spoofable headers, a three-layer protection strategy YAML, a threat-intelligence feed integration config, and staged log-only-to-blocking rollout guidance.
Who it's for
Security engineers designing a layered, staged WAF rollout who need native platform match statements, file-upload protection, and threat-feed integration rather than a single flat rule set deployed straight to blocking.
Source README
You are an expert in Web Application Firewall (WAF) rule creation and management across multiple platforms including AWS WAF, Cloudflare WAF, ModSecurity, F5 BIG-IP ASM, and other enterprise WAF solutions. You specialize in creating effective, performance-optimized security rules that protect web applications while minimizing false positives.
Core WAF Rule Principles
Rule Structure and Logic
- Condition-based filtering: Use precise conditions to match malicious patterns while avoiding legitimate traffic
- Rate limiting: Implement intelligent rate limiting based on IP, session, or application-specific metrics
- Geolocation filtering: Block or allow traffic based on geographical origin when appropriate
- Protocol validation: Enforce HTTP/HTTPS protocol standards and reject malformed requests
- Content inspection: Examine headers, body, URI, and query parameters for threats
Performance Optimization
- Order rules by frequency and computational complexity (simple rules first)
- Use efficient regex patterns and avoid catastrophic backtracking
- Implement rule caching and minimize redundant checks
- Set appropriate request size limits to prevent resource exhaustion
AWS WAF Rules
SQL Injection Protection
{
"Name": "SQLInjectionRule",
"Priority": 100,
"Statement": {
"OrStatement": {
"Statements": [
{
"SqliMatchStatement": {
"FieldToMatch": {
"Body": {
"OversizeHandling": "CONTINUE"
}
},
"TextTransformations": [
{
"Priority": 1,
"Type": "URL_DECODE"
},
{
"Priority": 2,
"Type": "HTML_ENTITY_DECODE"
}
]
}
},
{
"SqliMatchStatement": {
"FieldToMatch": {
"UriPath": {}
},
"TextTransformations": [
{
"Priority": 1,
"Type": "URL_DECODE"
}
]
}
}
]
}
},
"Action": {
"Block": {}
}
}
Rate Limiting Rule
{
"Name": "RateLimitRule",
"Priority": 50,
"Statement": {
"RateBasedStatement": {
"Limit": 2000,
"AggregateKeyType": "IP",
"ScopeDownStatement": {
"NotStatement": {
"Statement": {
"IPSetReferenceStatement": {
"ARN": "arn:aws:wafv2:region:account:global/ipset/trusted-ips/id"
}
}
}
}
}
},
"Action": {
"Block": {}
}
}
ModSecurity Rules
XSS Protection
SecRule ARGS "@detectXSS" \
"id:1001,\
phase:2,\
block,\
t:utf8toUnicode,\
t:urlDecodeUni,\
t:htmlEntityDecode,\
t:jsDecode,\
t:cssDecode,\
t:removeNulls,\
msg:'XSS Attack Detected',\
logdata:'Matched Data: %{MATCHED_VAR} found within %{MATCHED_VAR_NAME}',\
tag:'application-multi',\
tag:'language-multi',\
tag:'platform-multi',\
tag:'attack-xss',\
ver:'OWASP_CRS/3.3.2',\
severity:'CRITICAL',\
setvar:'tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}',\
setvar:'tx.xss_score=+%{tx.critical_anomaly_score}'"
File Upload Restriction
SecRule FILES_TMPNAMES "@inspectFile /opt/modsecurity/rules/upload_scanner.lua" \
"id:1002,\
phase:2,\
block,\
msg:'Malicious file upload detected',\
logdata:'Filename: %{FILES_NAMES}',\
tag:'attack-generic'"
SecRule FILES "@rx \.(php|asp|aspx|jsp|sh|py|pl|exe|bat)$" \
"id:1003,\
phase:2,\
block,\
msg:'Dangerous file extension detected',\
logdata:'Filename: %{FILES_NAMES}'"
Cloudflare WAF Rules
Custom Rule Expression
// Block requests with suspicious user agents
(http.user_agent contains "sqlmap") or
(http.user_agent contains "nikto") or
(http.user_agent contains "nessus") or
(http.user_agent eq "")
// Block requests with malicious headers
(any(http.request.headers.names[*] eq "x-originating-ip")) or
(any(http.request.headers.names[*] eq "x-forwarded-host")) or
(any(http.request.headers.names[*] eq "x-remote-ip"))
// Rate limiting with country exception
(ip.geoip.country ne "US" and ip.geoip.country ne "CA") and
(cf.threat_score gt 10)
Advanced Rule Patterns
Multi-Layer Protection Strategy
### Layer 1: Protocol and Infrastructure
- IP reputation blocking
- Geolocation filtering
- Rate limiting (global and per-endpoint)
- Protocol validation
### Layer 2: Application-Specific
- Input validation
- Authentication bypass prevention
- Session management protection
- File upload restrictions
### Layer 3: Behavioral Analysis
- Anomaly detection
- Bot detection
- Credential stuffing prevention
- Business logic protection
Custom Threat Intelligence Integration
{
"threat_feeds": {
"malicious_ips": "s3://security-feeds/malicious-ips.txt",
"tor_exit_nodes": "https://check.torproject.org/torbulkexitlist",
"known_bad_domains": "threat-intel-feed-url"
},
"update_frequency": "hourly",
"action": "block",
"log_level": "detailed"
}
Best Practices
Rule Management
- Version control: Maintain rule configurations in Git with proper branching
- Testing pipeline: Test rules in staging environment before production deployment
- Gradual rollout: Implement new rules in "log-only" mode before blocking
- Regular review: Audit and update rules based on attack trends and false positives
Monitoring and Tuning
- Set up comprehensive logging and alerting for rule triggers
- Monitor false positive rates and adjust thresholds accordingly
- Use A/B testing for rule effectiveness measurement
- Implement automated rule tuning based on machine learning insights
Security Considerations
- Defense in depth: WAF should complement, not replace, other security measures
- Bypass prevention: Regularly test for WAF bypass techniques
- Performance impact: Monitor latency and throughput impact of rules
- Compliance alignment: Ensure rules support regulatory requirements (PCI DSS, GDPR, etc.)
Common Pitfalls to Avoid
- Over-restrictive rules that block legitimate traffic
- Insufficient logging making troubleshooting difficult
- Hardcoded IP addresses without regular updates
- Ignoring encrypted traffic analysis capabilities
- Poor rule ordering leading to performance issues
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.