Any application exposed to the internet receives automated traffic all the time (scans, exploitation attempts, abuse). AWS WAF, placed together with CloudFront, filters that traffic at the edge, before it reaches your origin. Turning on the WAF is easy. The real work is tuning it to stop real attacks without blocking legitimate customers.
With WAF and CloudFront together, that tuning comes down to a few practical decisions: which rules to use, how to reduce false positives with scope-down statements, when Bot Control is worth it, and how to introduce blocking without knocking anyone offline. You also need to protect the origin against bypass and use the logs for ongoing tuning.
Managed rules and count mode
Start with the AWS managed rule groups, which cover common categories such as malicious input, IP reputation, and OWASP patterns. Before blocking anything, keep the rules in count mode and measure the impact on your real traffic. This step avoids the classic mistake of deploying aggressive blocks and locking out legitimate users on day one.
With the counts in hand, promote the rules with a low false positive rate to block. Those that catch legitimate traffic stay in count mode or get adjusted. Plan for this adjustment (the tuning) as a recurring task that repeats for as long as the application is online.
Sometimes a managed rule catches the attack but also hits a legitimate route. In that case, avoid turning it off entirely. Use a scope-down statement to apply it only where it makes sense, or disable just the specific rule inside the group, by its label. That way you fix the problem on that path without giving up protection on the rest of the application.
Rate limiting and login protection
Rate-based rules limit how many requests a single source can make within a time window, which holds back brute force and abuse. On authentication pages, combine rate limiting with stricter rules and, where available, with challenges. Always watch the effect on real users, because in a company many people reach the internet through the same corporate IP.
Geoblocking can reduce noise when your audience is regional, but use it carefully, because legitimate users travel and use VPNs. Think of geoblocking as a way to reduce the surface, not as a definitive security control.
Bots and credential abuse
For more sophisticated automated traffic, AWS WAF offers paid managed rule groups. Bot Control sorts bots by category, and the account takeover prevention group watches login and sign-up patterns to stop credential stuffing. They pay off for applications that suffer authentication abuse, but they are billed by volume and need careful calibration. Here too, it is worth starting in count mode and measuring the effect on real users before blocking.
Origin protection and logs
Filtering at the edge is pointless if the origin accepts direct connections that go around CloudFront and the WAF. With an S3 origin, use Origin Access Control: the bucket stays private and only accepts access through the distribution. With an ALB or your own server as the origin, validate at the origin a secret header that only CloudFront sends, and restrict the security group to the CloudFront managed prefix list. Without that, an attacker only has to discover the origin address to skip the edge.
Enable WAF logging and send the logs for analysis. They show which rules are acting, which requests were blocked, and where false positives occur. You tune the rules based on them, and they are what helps the investigation when an attack gets through.
Practical checklist
- Associate the WAF with the CloudFront distribution in front of the application
- Enable the managed rules that fit the application stack
- Deploy new rules in count mode first and measure the impact
- Promote to block only the rules with few false positives
- Apply rate limiting to sensitive endpoints and login endpoints
- Reduce false positives with scope-down statements and label-based tuning instead of turning off entire rules
- Evaluate Bot Control and account takeover prevention where there is authentication abuse
- Evaluate geoblocking according to your audience, without treating it as the only control
- Lock down the origin with OAC on S3, or with a secret header and the prefix list on the ALB
- Enable WAF logs and send them for analysis
- Review the rules and the false positives from time to time
- Document exceptions and custom rules
Best practices
- Treat WAF tuning as an ongoing process that repeats for as long as the application is online
- Use count mode before any new block
- Protect the origin against direct access that skips the edge
- Combine rate limiting with specific rules on the login page
- Track blocking metrics to detect attack campaigns
- Remember that the WAF mitigates attacks, but the flaw in the application stays there until it is fixed
Common mistakes
- Deploying blocks without a count phase
- Legitimate users get blocked and the WAF loses credibility inside the company.
- Origin that accepts direct connections
- The attacker bypasses CloudFront and the WAF and goes straight for the origin.
- Geoblocking treated as definitive security
- It gives a false sense of protection and blocks legitimate users who are traveling or behind a VPN.
- WAF without logs
- There is no way to tune it or to investigate what was blocked and what got through.
- Trusting the WAF and ignoring the application
- Application flaws stay exploitable whenever a request gets past the edge.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.