SkillSprout
Chapter 10 · Lesson 5
Intermediate
7 min read

WAF

Overview

AWS WAF (Web Application Firewall) protects web applications and APIs from common exploits at Layer 7 (HTTP/HTTPS). It inspects each request and decides to allow, block, count or challenge it based on rules you define, such as "block requests with SQL injection patterns", "allow only these countries" or "limit each IP to 2,000 requests in 5 minutes".

Think of a bouncer at a club door who reads every visitor's request and checks it against a list of rules. Network firewalls (security groups and NACLs) only look at IPs and ports; WAF understands URIs, headers, query strings and bodies.

WAF attaches to CloudFront, Application Load Balancer, API Gateway (REST), AppSync, Cognito user pools and other front-door services. It is the exam answer whenever you see SQL injection, cross-site scripting, bots or rate limiting for a web application.

Key Concepts

  • WAF operates at Layer 7 and protects against SQL injection, XSS, bad bots, and abusive request rates.
  • A web ACL contains ordered rules (or rule groups) and a default action (allow or block); rule actions are Allow, Block, Count, CAPTCHA, Challenge.
  • Attach a web ACL to CloudFront, ALB, API Gateway REST API, AppSync, Cognito user pool, App Runner, Verified Access. It does not attach to NLB or EC2 directly.
  • Managed rule groups (AWS and Marketplace vendors) cover OWASP-style threats; Bot Control and Fraud Control (ATP/ACFP) are optional paid groups.
  • Rate-based rules limit requests from an IP (or aggregated key) over a time window; used for HTTP floods and brute force.
  • Rules can match IP sets, geo location, headers, URI, query string, body, regex patterns, labels.
  • Web ACL capacity units (WCUs): each rule consumes WCUs; default limit 1,500 per web ACL (can be raised).
  • WAF for CloudFront is global (created in us-east-1); WAF for ALB/API Gateway is regional.

Detailed Notes

Where WAF sits

text
Client -> [CloudFront + WAF] -> ALB -> targets
Client -> [ALB + WAF]        -> targets
Client -> [API Gateway + WAF] -> Lambda / backend

WAF inspects the request before it reaches your application. Because it works at the edge on CloudFront, malicious traffic is blocked close to the user, reducing load on your origin.

Web ACLs, rules and rule groups

A web ACL evaluates rules in priority order (lowest number first). The first rule that matches with a terminating action (Allow or Block) decides the outcome; Count only logs and continues. If nothing matches, the default action applies.

ConceptDescription
RuleA condition (statement) plus an action
Rule groupA reusable set of rules (own, AWS-managed, or Marketplace)
IP setA list of IPv4/IPv6 CIDRs to allow or block (up to 10,000 addresses per set)
Regex pattern setReusable regular expressions
LabelsTags that rules add to requests so later rules can act on them
ActionsAllow, Block, Count, CAPTCHA, Challenge

Managed rule groups

  • Core rule set (CRS) - OWASP Top 10 style protections (XSS, bad inputs).
  • SQL database - SQL injection patterns.
  • Known bad inputs - Log4j and similar exploits.
  • Amazon IP reputation list and Anonymous IP list - botnets, Tor, VPN/proxy hosting.
  • Bot Control and Account takeover prevention (ATP) - paid, targeted bot and credential-stuffing protection.

Rate-based rules

A rate-based rule counts requests per aggregation key (source IP by default, or header/forwarded IP) over a configurable window (1, 2, 5 or 10 minutes) and applies an action once the limit is exceeded. It is perfect for brute-force login protection and HTTP flood mitigation.

json
{
  "Name": "rate-limit-per-ip",
  "Priority": 1,
  "Statement": {
    "RateBasedStatement": { "Limit": 2000, "AggregateKeyType": "IP", "EvaluationWindowSec": 300 }
  },
  "Action": { "Block": {} },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "RateLimitPerIp"
  }
}

Logging and monitoring

  • Enable WAF logging to S3, CloudWatch Logs or Kinesis Data Firehose (full request details; redact sensitive fields).
  • CloudWatch metrics show allowed/blocked/counted requests per rule. Sampled requests show recent matches.
  • Start new rules in Count mode to test impact before switching to Block.

Centralised management

AWS Firewall Manager applies WAF rules and web ACLs across accounts in an AWS Organization, and automatically protects new resources. It also manages Shield Advanced, security groups and Network Firewall policies.

Limits and boundaries

  • WAF inspects up to the first 8 KB (CloudFront: 16 KB, configurable up to 64 KB) of a request body by default; oversize handling is configurable.
  • WAF does not protect against Layer 3/4 DDoS - that is Shield. It also does not replace patching or input validation.
  • To restrict access to a specific CIDR you can use WAF IP match; to block a single malicious IP at subnet level use a NACL.

Common patterns

  1. CloudFront + WAF + ALB for global sites; lock the ALB so only CloudFront can reach it (custom header or managed prefix list).
  2. Geo restriction to allow only licensed countries.
  3. Block countries/IPs from admin paths, such as /admin.

Real World Example

Scenario — a ticketing company survives an on-sale rush with bots and attacks.

A concert ticketing site sits behind CloudFront and an ALB. During high-demand sales, scalper bots hammer the login and checkout endpoints, and security tools show SQL injection probes against the search page.

The team attaches an AWS WAF web ACL to the CloudFront distribution with:

  1. AWSManagedRulesCommonRuleSet and SQLiRuleSet in Block mode for exploit protection.
  2. Bot Control (targeted level) with CAPTCHA/Challenge actions on checkout.
  3. A rate-based rule limiting each IP to 300 requests per 5 minutes to /login.
  4. A geo-match rule that blocks countries where tickets are not sold.

Logs stream through Firehose to S3, queried with Athena. New rules start in Count mode before enforcement. Firewall Manager applies the same baseline to every brand account. The result is a major reduction in bot traffic and zero successful injection attacks, while legitimate buyers see no friction.

Architecture Diagram

CloudFront and WAF protecting an ALB-based application
Architecture
AWS Cloud
Customers
Bots / attackers
CloudFrontedge cache
AWS WAFweb ACL
Region
VPC
ALB
Web servers
WAF logs

WAF evaluates each HTTP request at the edge and again at the load balancer.

  1. 1Clients send HTTPS requests to CloudFront, which hands each one to the associated web ACL.
  2. 2WAF evaluates rules in priority order: managed rule groups, rate-based rules, geo and IP rules.
  3. 3Blocked requests receive a 403 response at the edge; allowed requests reach the ALB and the web servers.
  4. 4WAF logs go to S3 (via Firehose) and metrics to CloudWatch for tuning and alerting.

Best Practices

  • ✓Start with AWS managed rule groups (Core, SQLi, Known bad inputs, IP reputation) and tune with exclusions.
  • ✓Deploy new rules in Count mode first, review logs, then move to Block.
  • ✓Add rate-based rules for login, search and API endpoints.
  • ✓Attach WAF to CloudFront where possible so attacks are stopped at the edge; restrict the origin to CloudFront only.
  • ✓Enable logging (Firehose/S3/CloudWatch) with redaction of sensitive headers and cookies.
  • ✓Use Firewall Manager to enforce a baseline web ACL across all accounts.
  • ✓Combine with Shield Advanced for DDoS and with proper application security.
  • ✓Manage web ACLs as code (CloudFormation/Terraform) and monitor WCU usage.

Common Interview Questions

Exam Tips

SAA-C03 focus

  • SQL injection, XSS, bad bots, HTTP floods at the application layer -> AWS WAF (Layer 7).
  • Attach points: CloudFront, ALB, API Gateway, AppSync, Cognito. Not NLB.
  • Block specific countries -> WAF geo-match rule (or CloudFront geo restriction); block a specific IP -> WAF IP set or NACL.
  • Rate limiting per IP -> rate-based rule.
  • WAF for CloudFront is global, but the web ACL is created in us-east-1.
  • Layer 3/4 DDoS -> Shield; Layer 7 -> WAF; both together for full protection.
  • Manage WAF across an organisation -> AWS Firewall Manager.
  • Test rules in Count mode first; log to S3, CloudWatch Logs or Firehose.

Finished this lesson?

0 of 64 lessons done · 0% of the course