Lesson 1 of 4 AWS WAF, AWS Shield and Amazon CloudFront

Filtering Web Requests with AWS WAF

This lesson explains how AWS WAF, a web application firewall, inspects HTTP and HTTPS requests to CloudFront, Application Load Balancers, API Gateway, AppSync, Cognito user pools and Verified Access, and allows, blocks or challenges them.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how a web ACL evaluates rules in priority order and applies actions.
  • Choose managed rule groups for common threats.
  • Configure rate-based rules with custom aggregation keys.
  • Explain how new rules are rolled out in count mode and their results logged.

Web ACLs and rules

A web ACL holds rules evaluated in priority order; a default action applies when none match.

When a rule matches, its action decides what happens. Allow lets the request through, and Block rejects it, normally with a 403 response; both stop evaluation. Count only records that the rule matched and lets evaluation continue, which is how a new rule is tested against real traffic before it can block legitimate users. CAPTCHA shows a visible puzzle that a person must solve. Challenge runs a silent browser check that most real browsers pass without the user noticing, but simple bots fail. The following table summarises the actions.

ActionEffect
Allow / BlockLet through or reject
CountRecord only; used to test rules
CAPTCHAVisible puzzle
ChallengeSilent browser challenge

Rules match IP sets, geography, headers, cookies, query strings, body, URI, regex, labels from earlier rules, and built-in SQL injection and XSS detection.

Match the pairs

WAF rule actions

Exam skills 3.1.2

Match each AWS WAF rule action with its effect.

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

Managed rule groups

Managed rule groups are rule sets maintained by AWS, which you add to a web ACL instead of writing rules yourself. The core rule set gives broad protection against common web attacks in the OWASP Top 10. Use-case groups, such as known bad inputs, SQL database and the Linux, Windows and PHP groups, block exploit patterns for particular technologies, so you add the ones that match your application.

IP reputation groups block traffic by its source. The Amazon IP reputation list covers addresses known to be malicious, and the anonymous IP list covers VPNs, Tor exit nodes and hosting providers that attackers use to hide. The paid intelligent threat groups go further. Bot Control detects common bots and, at its targeted level, sophisticated ones. Account Takeover Prevention protects login pages against credential stuffing, and Account Creation Fraud Prevention stops fake sign-ups. The following table summarises the groups.

Rule groupProtects against
Core rule setBroad OWASP Top 10 coverage
Known bad inputs, SQL database, Linux/Windows/PHPSpecific exploit patterns
Amazon IP reputation listKnown malicious IPs
Anonymous IP listVPNs, Tor, hosting providers
Bot ControlCommon and targeted bots
Account Takeover PreventionCredential stuffing on login pages
Account Creation Fraud PreventionFake sign-ups

AWS Marketplace sellers offer further groups.

Sort into groups

Which managed rule group?

Exam skills 3.1.2 · 3.1.1 · 3.1.4

Choose the AWS WAF managed rule group that addresses each threat.

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

Rate-based rules

Count requests over a window and act on clients exceeding a limit. Aggregate by IP, forwarded IP, or custom keys (header, cookie, query argument, label namespace, JA3/JA4 TLS fingerprint), optionally scoped to paths like /login.

The following diagram compares a rate-based rule that aggregates by IP address with one that aggregates by JA4 TLS fingerprint, against a credential-stuffing attack from many addresses.

Aggregating a rate-based rule on the TLS fingerprint. A per-IP limit never triggers because each residential address sends only a few requests, but the attack tool presents the same JA4 fingerprint everywhere. A rule keyed on JA4 and scoped to /login, started in Count mode, then set to Block or CAPTCHA, catches it.
ATP stands for Account Takeover Prevention.
True or false

Rate-based rules

Exam skills 3.1.3

Check how rate-based rules aggregate and scope requests.

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

Rolling out and logging

New AWS WAF rules should be introduced gradually to avoid blocking legitimate traffic. The recommended procedure is as follows.

  1. Count

    Deploy new rules in Count mode.

  2. Review

    Check logs and sampled requests for false positives.

  3. Block

    Switch to Block; fine-tune managed rules with scope-down statements and rule action overrides.

Logs go to CloudWatch Logs, S3 or Firehose with redaction; destination names must start with aws-waf-logs-. CloudWatch metrics show counts per rule.

Scenario questions

Rolling out WAF rules

Exam skills 3.1.2

Apply the recommended rollout and logging practices.

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

Stopping credential stuffing that rotates IP addresses

A login endpoint receives thousands of attempts an hour from residential IP addresses, each sending only a few requests, so a per-IP rate limit never triggers. The attack tool, however, presents the same TLS fingerprint everywhere. A rate-based rule aggregated on the JA4 fingerprint, scoped to the login path, catches it:

{
  "Name": "login-by-ja4",
  "Priority": 5,
  "Statement": {
    "RateBasedStatement": {
      "Limit": 300,
      "EvaluationWindowSec": 300,
      "AggregateKeyType": "CUSTOM_KEYS",
      "CustomKeys": [{ "JA4Fingerprint": { "FallbackBehavior": "MATCH" } }],
      "ScopeDownStatement": {
        "ByteMatchStatement": {
          "FieldToMatch": { "UriPath": {} }, "SearchString": "/login",
          "PositionalConstraint": "STARTS_WITH",
          "TextTransformations": [{ "Priority": 0, "Type": "LOWERCASE" }]
        }
      }
    }
  },
  "Action": { "Count": {} },
  "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "LoginJa4" }
}

The rule starts in Count mode. Once sampled requests confirm that legitimate browsers stay below the limit, the action becomes Block or CAPTCHA. For continuous protection against stolen-credential lists, the managed Account Takeover Prevention group inspects the login request itself and checks credentials against known compromised sets.

Check yourself

Which managed rule groups protect against SQL injection and cross-site scripting?

Show answer

The Core rule set and the SQL database rule group, among other AWS managed rules.

Exam Tips

Remember for the exam

  • For protection against SQL injection and XSS, use managed rule groups such as the Core rule set and SQL database.
  • If a new rule might block real users, deploy it in Count mode first.
  • For credential stuffing on a login page, use Account Takeover Prevention or a scoped rate-based rule.
  • When clients rotate IP addresses, rate-limit or block by JA3 or JA4 fingerprint.
  • WAF log destination names must start with aws-waf-logs-.
  • To block known malicious and anonymising IP addresses, use the IP reputation and Anonymous IP lists.