Lesson 1 of 3 AWS WAF, Shield and Firewall Manager

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.

SupportedNot supported
CloudFront, ALB, API Gateway REST APIs, Cognito user poolsNLB, EC2 instances directly

The following diagram shows the resources a web ACL can and cannot be associated with.

Where AWS WAF can be associated. Because it inspects HTTP and HTTPS requests, a web ACL attaches to CloudFront distributions, Application Load Balancers, API Gateway REST APIs and Cognito user pools. It cannot attach to a Network Load Balancer or directly to an EC2 instance, so those must be fronted by CloudFront or an ALB.
To protect an application behind an NLB or on an instance, put CloudFront or an ALB in front of it and attach the web ACL there.

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.

Match the pairs

WAF rules

Exam skills 1.2.3

Match each threat with the AWS WAF feature that addresses it.

Log in to try this activity Interactive activities are free with an account.

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.

Put in order

Rolling out a WAF rule

Exam skills 1.2.3

Put the steps of rolling out a new WAF rule safely in order.

Log in to try this activity Interactive activities are free with an account.

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.

Preventing WAF bypass. WAF on CloudFront filters requests at the edge. The ALB's security group allows inbound traffic only from CloudFront's managed prefix list, so an attacker who calls the ALB directly is refused and cannot skip the web ACL.
Without the rule, the ALB's public DNS name would be a second, unfiltered way in.
Troubleshooting scenario

Bypassing the firewall

Exam skills 1.2.3 · 1.2.1

Close the gaps that let traffic bypass AWS WAF.

Log in to try this activity Interactive activities are free with an account.
Worked example

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:

RulePurpose
AWS managed Core rule set and SQL database rule groupBlock common exploits and SQL injection
Rate-based rule: more than 100 requests in 5 minutes to /login per IPBlock brute-force attempts
Amazon IP reputation listBlock known malicious addresses
Geo matchBlock 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.

Check yourself

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.