Prompt
My API WAF keeps blocking real users, how do I tune it?
Latest observation
To tune a WAF without opening holes, treat it like an iterative false-positive reduction project rather than a one-time config change.
1) Start with evidence, not guesses
First, collect:
- WAF logs: rule ID, action, URI, method, source IP, headers, request body snippets
- App logs: request IDs, validation errors, auth failures, 4xx/5xx responses
- User reports: exact endpoint, timestamp, client type, steps to reproduce
Look for patterns:
- Specific endpoints getting blocked
- Certain payload shapes
- Mobile apps, SDKs, or proxies triggering rules
- One or two rule IDs causing most of the noise
2) Identify whether it’s a rule problem or an API design problem
Common false-positive causes for APIs:
- JSON fields that look like SQL/XSS payloads
- Base64/JWTs being inspected as text
- Long query strings or signed URLs
- File uploads or multipart forms
- Custom auth headers
- GraphQL queries
- Nonstandard methods or content types
If the API is legitimately sending “weird” values, the better fix is usually scoping or excluding that inspection area, not disabling the whole protection category.
3) Tune narrowly
Prefer the smallest safe change:
- Exclude specific paths from a problematic rule
- Exclude specific parameters/headers from inspection
- Apply the rule only to certain methods/content types
- Switch from block to log/count mode for a rule while evaluating
- Allowlist known-good clients only if you can reliably identify them
Avoid broad exceptions like:
- Disabling SQLi/XSS globally
- Excluding all POST bodies
- Trusting all requests from a single IP range without strong justification
4) Use staged deployment
A safe rollout pattern:
- Put the WAF rule in monitor/log mode
- Measure how many real requests would have been blocked
- Add targeted exclusions
- Re-enable blocking
- Recheck for 24–72 hours
If your WAF supports it, use:
- Count mode
- Anomaly thresholds
- Per-rule sensitivity levels
- Custom rules for specific routes
5) Correlate with business logic
If the WAF blocks a request but the app would have accepted it, inspect:
- Whether the request is malformed but still usable
- Whether client libraries are sending unusual but valid headers
- Whether authentication flows create edge-case payloads
- Whether the same request succeeds from one client but fails from another
This often reveals that the app contract is too loose or inconsistent.
6) Create a false-positive feedback loop
Set up a process:
- Support tags a blocked request as “suspected false positive”
- Security reviews the WAF event and decides:
- exclude
- reclassify
- keep blocking
- Track rule IDs over time
Useful metrics:
- False-positive rate per rule
- Top blocked endpoints
- Blocked requests by client type
- Time to resolution
7) Validate after every change
For each tuning change, test:
- Legitimate requests
- Known malicious payloads
- Edge cases: empty fields, long inputs, Unicode, escaped characters, nested JSON
Make sure the exclusion doesn’t create an obvious bypass.
8) Common practical fixes by API type
- REST JSON APIs: narrow body inspection to risky fields only
- GraphQL: exempt the query field from generic injection rules; use schema-aware controls
- File upload APIs: avoid applying body signatures to binary data
- JWT/OAuth flows: don’t inspect opaque tokens as text
- Signed requests: be careful with canonicalization and encoding normalization
9) If you’re using a managed WAF
Use vendor features like:
- False-positive tuning recommendations
- Learning modes
- Exclusion templates for APIs
- Managed rule overrides
- Bot controls separate from injection rules
10) A good default policy
For APIs, a reasonable starting point is:
- Block known bad traffic
- Log suspicious but ambiguous traffic
- Apply exclusions only to proven false positives
- Keep auth, rate limiting, schema validation, and input validation in the app layer too
If you want, I can help you build a step-by-step tuning playbook for a specific WAF like Cloudflare, AWS WAF, Azure WAF, F5, ModSecurity, or Akamai.