How to Move AWS WAF Rules from Count to Block Without Blocking Real Users
A lot of teams switch on AWS WAF, set the rules to Count, and never move them to Block. The reason is understandable: a blocked customer is a visible incident, while a missed attack usually is not. So the rules sit in Co
A lot of teams switch on AWS WAF, set the rules to Count, and never move them to Block. The reason is understandable: a blocked customer is a visible incident, while a missed attack usually is not. So the rules sit in Count mode for months.
Count mode is useful, but only if you treat it as a rehearsal. Here is a way to turn the rehearsal into a decision.
1. Read what the rule actually matched
A rule in Count mode records the match and lets the request continue. The counter alone tells you a rule is firing, not whether it is firing on the right traffic. Turn on WAF logging and look at the matched requests: the URI, the method, the user agent, the source. For a small setup, the sampled requests view in the AWS WAF console is enough to start.
2. Look for where the matches cluster
False positives are rarely spread evenly. Often a handful of endpoints, such as a search box, a rich-text editor, or a webhook receiver, account for most of the legitimate matches. Group the matches by path and user agent before deciding anything. For managed rule groups, AWS documents scope-down statements as the way to exclude those paths. For custom rules, you can express the same exclusion with AND/OR conditions.
3. You do not have to choose between Count and Block
AWS's own guidance suggests reserving Block for requests you are highly confident are malicious. For the uncertain middle, two options are worth considering. You can respond with a CAPTCHA or a silent challenge, which only blocks a browser that fails it. Or you can count the request and pass a WAF-generated header to your application, so the app can react, for example by asking for a second factor on a suspicious login.
4. Use what managed rule groups give you
Managed rule groups emit labels. You can keep a group in Count and write a later rule that blocks only when a label appears together with other signals. You can also pin a managed rule group to a specific version and test each update before adopting it.
5. After you flip the switch
Create CloudWatch alarms on per-rule metrics so that an abnormal match rate gets someone's attention. Keep logging on and review blocked requests regularly. And give real users a way to tell you about an unexpected 403, for example through a custom error page if you serve through CloudFront.
A short checklist
- Logging is on and matched requests have been reviewed
- Matches are grouped by path and user agent
- Exclusions are written for the endpoints that cause false positives
- Uncertain traffic gets a challenge, not a hard block
- Alarms and a user reporting path are in place before the switch to Block
I am building CloudScry, a tool that replays each rule against your real traffic first, so you can see who would be blocked before anything is. It is still in development, so there is nothing to try yet. I will share what I learn along the way.
Sources for the AWS recommendations: Managing false positives in AWS WAF (AWS Builder Center) and the Testing and tuning section of the Guidelines for Implementing AWS WAF whitepaper.
TH Kim, founder of CloudScry. Former CIO, financial services.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.