HTTP status code matching
Many WAFs return specific status codes when blocking malicious requests:- 403 Forbidden - Most common blocking response
- 404 Not Found - Some WAFs return 404 to hide blocking behavior
- 406 Not Acceptable - Used by certain WAFs for content filtering
- 418 I’m a teapot - Occasionally used as a blocking signal
HttpResponse type provides helper methods for status code checks:
Header pattern matching
HTTP response headers often contain vendor-specific signatures:Header existence checks
Detect WAFs by checking if specific headers are present:src/detectors/datadome.rs:13):
Header value matching
Detect WAFs by matching text within header values:src/detectors/arvancloud.rs:13):
Cookie-based detection
Many WAFs set tracking cookies: Real example - Incapsula detector (src/detectors/incapsula.rs:13):
Set-Cookie header contains either “incap_ses” or “visid_incap”.
Regex header matching
For complex patterns, detectors can use regular expressions:Response body pattern matching
WAF blocking pages often contain distinctive text or HTML structures.Simple text matching
Detect keywords in the response body:src/detectors/cloudflare.rs:13):
- Body contains BOTH phrases (“Sorry, you have been blocked” AND “Cloudflare Ray ID”)
- HTTP status is 403 Forbidden
Regex body matching
For variable content like IDs or timestamps, use regex patterns: Real example - FortiWeb detector (src/detectors/fortiweb.rs:9):
- Body contains the static HTML
<h2 class="fgd_icon">block</h2> - Body matches the regex for “Attack ID: 2XX” pattern
r"Attack ID:\s*2(?:0*\d{2})" matches FortiWeb attack identifiers documented in their log message reference.
Combining multiple patterns
Reliable detection combines multiple indicators to avoid false positives.AND logic (all conditions must match)
Example - Barracuda detector (src/detectors/barracuda.rs:13):
- Body contains “Barracuda Networks” AND
- Status code is 404
OR logic (any condition matches)
Match modes
TheMatchMode enum controls how multiple patterns are evaluated:
Detection reliability
To maximize accuracy:- Combine techniques - Use multiple detection methods together
- Use specific patterns - Match vendor-specific text or headers
- Verify status codes - Ensure blocked requests return expected codes
- Test with multiple probes - whatwaf sends XSS, SQLi, and LFI payloads to trigger blocking
Performance considerations
- Lazy regex compilation - Use
once_cell::sync::Lazyto compile patterns once - Case-insensitive matching - All text matching is case-insensitive by default
- Parallel detection - All detectors run independently and can be evaluated in parallel
- Short-circuit evaluation - Rust’s
&&and||operators short-circuit for efficiency