Filtering Web Exploits with AWS WAF
This lesson explains how AWS WAF protects web applications from common exploits by filtering HTTP and HTTPS requests at layer 7.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the resources WAF can protect.
- Describe managed rules, rate-based rules and custom rules.
- Explain how count mode supports a safe rule rollout.
- Explain how to stop attackers bypassing WAF.
Where WAF attaches
AWS WAF inspects HTTP and HTTPS requests, so it can be associated only with resources that receive web traffic at the application layer: CloudFront distributions, Application Load Balancers, API Gateway REST APIs and Cognito user pools. It cannot be attached to a Network Load Balancer, which forwards TCP and UDP without examining HTTP, or directly to an EC2 instance. An application that needs WAF protection behind an NLB or on an instance must be fronted by CloudFront or an ALB. The following table summarises the supported resources.
| Supported | Not supported |
|---|---|
| CloudFront, ALB, API Gateway REST APIs, Cognito user pools | NLB, EC2 instances directly |
The following diagram shows the resources a web ACL can and cannot be associated with.

Rules
AWS WAF inspects HTTP and HTTPS requests using rules grouped in a web ACL, which is attached to CloudFront, an Application Load Balancer, API Gateway or other supported resources. Rules can match IP addresses, through IP sets, the country of origin, headers, query strings, the request body and the URI, as well as patterns of SQL injection and cross-site scripting (XSS).
Rate-based rules block clients that exceed a request rate, which gives basic protection against HTTP floods and brute-force attempts. Managed rule groups, maintained by AWS and by AWS Marketplace sellers, provide ready-made protection: the core rule set against common vulnerabilities, known bad inputs, IP reputation lists, Bot Control and Account Takeover Prevention.
WAF rules
Actions and rollout
Each rule has an action: allow, block, count, which records matches without acting on them, CAPTCHA or challenge, which test whether the client is a browser operated by a person. Rules are evaluated in priority order, and the first matching rule with a terminating action decides the request's fate.
New rules are rolled out cautiously, because a rule that blocks legitimate traffic causes an outage. They are deployed in count mode first; the team reviews sampled requests and WAF logs, delivered to CloudWatch Logs, Amazon S3 or Amazon Data Firehose, to confirm that only unwanted traffic matches; and only then switches the rule to block. WAF is priced per web ACL, per rule and per million requests inspected.
Rolling out a WAF rule
Preventing bypass
WAF on CloudFront filters at the edge. Restrict the ALB's security group to CloudFront's managed prefix list so attackers cannot skip WAF by calling the ALB directly.
The following diagram shows the security group rule that closes the direct path.

Bypassing the firewall
Protecting a login page
An application's login page is attacked: SQL injection attempts, and one IP address sending thousands of login attempts a minute. The architect places AWS WAF on the CloudFront distribution:
| Rule | Purpose |
|---|---|
| AWS managed Core rule set and SQL database rule group | Block common exploits and SQL injection |
Rate-based rule: more than 100 requests in 5 minutes to /login per IP | Block brute-force attempts |
| Amazon IP reputation list | Block known malicious addresses |
| Geo match | Block countries where the company has no customers |
New rules start in Count mode to confirm they do not block real users. To stop attackers bypassing CloudFront and hitting the ALB directly, the ALB's security group allows only the CloudFront managed prefix list.
Which resources can an AWS WAF web ACL protect?
Show answer
CloudFront distributions, Application Load Balancers, API Gateway REST APIs and Cognito user pools, among others. It cannot be attached to a Network Load Balancer or directly to an EC2 instance.
Exam Tips
Remember for the exam
- For protection against SQL injection or XSS, use AWS WAF managed rules.
- To block requests from particular countries, use a WAF geo match rule or CloudFront geographic restrictions.
- WAF cannot be attached to an NLB; use it on an ALB, CloudFront or API Gateway.
- To throttle abusive IP addresses, use a rate-based rule.
- To test a rule without blocking traffic, use the count action and then switch to block.
- To stop attackers bypassing CloudFront and WAF, restrict the ALB to CloudFront's managed prefix list.