Wirefilter
Wirefilter is a powerful expression language used in our Web Application Firewall (WAF) to define complex rules and conditions for request filtering. It provides a flexible and intuitive way to create security rules based on various request attributes.
Overview
Wirefilter is a domain-specific language designed for: - HTTP request filtering - IP-based rules - Header-based conditions - Path and query string matching - Geographic location filtering
Basic Syntax
Operators
- Comparison:
eq
,ne
,gt
,lt
,ge
,le
- Logical:
and
,or
,not
- String:
contains
,starts_with
,ends_with
- List:
in
,not in
Examples
# Simple comparison
rule: (ip.src.country eq "US")
# Logical combinations
rule: (http.request.method eq "POST" and ip.src.country eq "FR")
# String matching
rule: (http.request.uri.path contains "/admin")
# List operations
rule: (ip.src in cidr("192.168.0.0/24"))
Supported Functions
Function | Description | Example |
---|---|---|
cidr() |
Check if IP is in CIDR range | ip.src in cidr("192.168.0.0/24") |
contains() |
Check if string contains substring | http.request.uri.path contains "/admin" |
starts_with() |
Check if string starts with prefix | http.request.uri.path starts_with "/api" |
ends_with() |
Check if string ends with suffix | http.request.uri.path ends_with ".php" |
Limitations
While Wirefilter is powerful, there are some limitations to be aware of:
- Function Support
- Not all Cloudflare Wirefilter functions are supported
- Some advanced functions may be unavailable
-
Custom functions are not supported
-
Field Differences
- Our implementation supports a subset of fields
- Some fields may have different names or behaviors
-
Please refer to our WAF Rules documentation for supported fields
-
Performance Considerations
- Complex rules may impact performance
- Avoid overly complex logical combinations
- Use specific conditions over broad matches
Best Practices
- Rule Organization
- Keep rules simple and focused
- Use meaningful names for rules
-
Document complex rule logic
-
Performance
- Use specific conditions when possible
- Avoid unnecessary complex expressions
-
Test rules in staging before production
-
Security
- Start with logging before blocking
- Use specific conditions over broad matches
- Regularly review and update rules
Additional Resources
Example Use Cases
# Block specific user agents
rule: (http.request.headers["user-agent"] contains "bad-bot")
# Protect admin paths
rule: (http.request.uri.path contains "/admin" and ip.src.country ne "US")
# Block specific HTTP methods
rule: (http.request.method eq "PUT" or http.request.method eq "DELETE")
# Geographic restrictions
rule: (ip.src.country in ["RU", "CN", "IR"])