Skip to content
Aesthetic Infra

    Attach AWS WAF in the right place and close the bypass

    Hieu Vu

    25 min read
    On this page

    AWS WAF only protects requests that pass through a resource with a Web ACL attached. Picking the right attachment point and closing direct access to the origin are two jobs you have to do together.

    ComponentRole
    Web ACLA set of rules with priorities and a default action; the unit you attach to a resource
    Rules and rule groupsConditions that inspect IP, URI, body, SQLi, XSS and request rate
    ActionAllow, Block, Count, CAPTCHA or Challenge
    Attachment pointA resource AWS WAF supports, not an arbitrary instance or pod

    Situation and definition

    AWS WAF is a web application firewall: it inspects every HTTP(S) request entering a supported AWS resource, then allows, blocks, counts or challenges it according to the rules you define.

    Situation: an online shop runs on EKS behind an ALB, has a mobile API on API Gateway and static files on S3. The security team asks to "turn on WAF for everything". The real question is where WAF can attach, and where the architecture has to change. (Illustrative scenario.)

    Goal of this post: afterwards you can place WAF in any architecture yourself, point out which paths still get through, and choose a substitute service when WAF cannot attach. Prerequisites: the parts of an HTTP request, and what a load balancer is.

    Simple: a guard at the door

    Every building has its own door. A guard stands at the door, checks each visitor's papers and decides whether to let them in or turn them away.

    Developer: a Web ACL attached to a resource

    Create a Web ACL with rules and attach it to an ALB, CloudFront or REST API. The resource calls WAF before handling the request; if WAF blocks it, the client gets a 403.

    Architect: the L7 layer in defense in depth

    WAF runs at the edge (CloudFront) or regionally (ALB). Combine it with Shield for L3/L4, Network Firewall for the VPC and Firewall Manager across accounts.

    Source: AWS WAF: supported resources.

    Picture it as

    Real life: a guard at the building door

    A guard stands at the building door, opens each letter, and checks it against a list of rules.

    AWS: a Web ACL attached to an ALB

    Building = resource (ALB, CloudFront). Guard = Web ACL. Rules = rules. Opening the letter = TLS decryption.

    Mechanism: a request through an ALB with WAF

    Predict before you look: does WAF run before or after the ALB's authenticate step (Cognito/OIDC)?

    Before. WAF inspects the request right after the ALB decrypts TLS, before listener rules and authenticate actions.

    Path of a request through an ALB with AWS WAF attached, 5 steps

    Request allowed

    1. Client HTTPS

    2. ALB: decrypt TLS

    3. Web ACL: Allow

    4. Listener rules / auth

    5. Target

    The response goes back to the client; WAF does not inspect the response.

    1. Step 1 The ALB terminates TLS. From here on, headers, URI, query, cookies and body are readable. This is why only the ALB (layer 7) can have WAF attached.
    2. Step 2 WAF evaluates rules by priority, lowest number first. The first matching rule with an Allow or Block action stops evaluation. Count only records the match and moves on. If no rule matches, the default action applies.
    3. Step 3 Only after WAF lets the request through does the ALB run listener rules (path/host, redirect, authenticate-cognito/oidc). A bot blocked in step 2 never reaches authentication.
    4. Step 4 The target receives the request with X-Forwarded-For carrying the client IP. WAF can add custom headers prefixed x-amzn-waf- when the action is configured for it. Labels are used by later rules and appear in logs; a label does not turn into a header sent to the app on its own.
    5. Step 5 WAF only inspects the request; it does not read the response body. Logs (CloudWatch Logs, S3, Firehose) record which rule matched and the final action.

    The diagram is a model of the processing order, not a description of AWS internal infrastructure. The frame highlighted in the primary colour marks the resource that has the Web ACL; WAF is not a standalone network proxy.

    Source: Rule priority, Labels in WAF.

    Integration map: what can and cannot attach

    WAF is not a network hop of its own. It can only attach to the resources in the table below. "WAF in front of service X" really means: X sits behind a resource that has WAF attached.

    Resource that can attachScopeBody inspectedNotes
    CloudFront distributionGlobal (us-east-1)16 KB, up to 64 KBBlocks at the edge, before the region
    Application Load BalancerRegional8 KB fixedInternal ALBs too. Not supported for ALBs in a Local Zone or on Outposts
    API Gateway REST APIRegional16 KB, up to 64 KBAttached per stage. HTTP APIs and WebSocket APIs cannot attach
    AppSync GraphQL APIRegional8 KB fixedLarge GraphQL queries easily exceed 8 KB
    Cognito user poolRegional16 KB, up to 64 KBProtects sign-in, sign-up and the hosted UI
    App Runner, Verified Access, Bedrock AgentCore GatewayRegional16 KB, up to 64 KBCheck availability per region
    Amplify HostingGlobal8 KB per the Amplify docsCheck Amplify's integration requirements
    Cannot attach directlyWhyUse instead
    NLBLayer 4, does not read HTTPNLB → ALB+WAF (case C); Network Firewall; Shield Advanced; security groups for the NLB
    GWLBLayer 3, for inserting appliancesThird-party appliance (NGFW/IPS) behind the GWLB
    Classic Load BalancerPrevious generationMigrate to ALB
    HTTP API, WebSocket APINot on the supported listCloudFront+WAF in front (case F) or a REST API
    Lambda URL, S3Not on the supported listCloudFront+WAF with OAC in front
    EC2/ECS/EKS directlyWAF does not attach to instances or podsALB (Ingress) or CloudFront VPC Origins

    More cases that are not HTTP or not ingress

    NeedWhy WAF cannot do itSuitable service
    TCP/UDP: games, MQTT, SMTP, databases, SSHThere is no HTTP request to inspectNetwork Firewall, Shield, SG/NACL, GWLB+appliance
    High-volume L3/L4 DDoSWAF filters L7; it does not absorb floodsShield Standard (default), Shield Advanced
    Blocking egress, malicious domainsWAF only looks at incoming requestsNetwork Firewall, Route 53 Resolver DNS Firewall
    Internal service-to-service trafficOnly works if traffic goes through an internal ALBInternal ALB+WAF; SG; VPC Lattice auth policy
    Inspecting responses, preventing data leaksWAF does not read the response bodyLogic in the app or a DLP solution
    Managing WAF across many accountsDoing it by hand misses thingsAWS Firewall Manager

    Source: Supported resources, Body inspection limit, WAF for Amplify Hosting.

    Elastic Load Balancing: only the ALB supports WAF

    LB typeLayerWAFIf you still need L7 filtering
    Application LB7 (HTTP/HTTPS, gRPC)YesAttach the Web ACL directly
    Network LB4 (TCP/UDP/TLS)NoPut an ALB as the NLB's target
    Gateway LB3 (GENEVE)NoThird-party appliance behind it
    Classic LB4/7 (legacy)NoMove to ALB

    What about large bodies?

    The ALB sends only the first 8 KB to WAF, and that cannot be raised. Choose oversize handling: Continue, Match or No match (case E).

    Is there a proxy in front?

    Behind a proxy, the source IP may be the proxy's IP. If you need the user's IP, choose a forwarded-IP configuration and decide which header you trust; do not assume the first IP in X-Forwarded-For is trustworthy.

    What if WAF fails?

    The waf.fail_open.enabled attribute defaults to false: the ALB does not forward requests when it cannot reach WAF.

    • Each ALB has at most 1 Web ACL. One Web ACL can be attached to many ALBs in the same region.

    • gRPC: body-inspection rules do not apply to gRPC requests. The other rules (headers, IP, URI) still run.

    • HTTP/2 to targets: the target group attribute "WAF HTTP/2 traffic inspection behavior" lets you inspect immediately (the default, suited to bidirectional streaming) or inspect after enough data has arrived to inspect. This setting does not raise the body limit.

    • EKS: the AWS Load Balancer Controller attaches WAF through the alb.ingress.kubernetes.io/wafv2-acl-arn annotation. When the AWS Load Balancer Controller provisions an NLB, a Service of type: LoadBalancer creates no WAF attachment point. The LB type also depends on the controller and cluster configuration.

    • WebSocket: WAF only inspects the initial upgrade request, not the frames sent afterwards.

    Source: ALB attributes, Body and HTTP/2 inspection, Ingress annotations.

    Six real-world cases: in front, behind, and the gaps

    CaseArchitectureBranch pointResult
    A · SQLi to the ALBClient → ALB[WAF] → EC2SQLi rule matches403, target never touched
    B · Bypassing CloudFrontCF[WAF] → public ALBCalling the ALB's DNS directlyGets through; lock the origin
    C · NLB → ALBNLB → ALB[WAF] → podALB as the NLB's targetStatic IP and WAF together
    D · WAF on an NLBNLB passthrough → podAssociation is rejectedNo L7 layer
    E · 20 KB bodyALB[WAF], oversize ContinueSees only the first 8 KBMay get through; use Match + Block
    F · HTTP APICF[WAF] → HTTP API → LambdaCloudFront stands inWAF in place; origin checks a header

    Pair 1 · WAF on the ALB blocks correctly, and a bypass makes WAF useless

    Case A · A SQLi request is blocked right at the ALB

    The Web ACL on the ALB has the managed rule group AWSManagedRulesSQLiRuleSet in Block mode. An attacker sends GET /items?id=1' OR '1'='1. (Illustrative scenario.)

    Predict before you run it: does the EC2 target receive this request?

    No. WAF matches the SQLi rule during inspection, the ALB returns 403 and does not forward the request to the target group.

    Case A: a SQL injection request is blocked by WAF on the ALB

    SQLi blocked

    1. Client SQLi

    2. ALB + Web ACL

    3. Block: HTTP 403

    The target receives nothing when the SQLi rule matches and the action is Block.

    1. Step 1 The request crosses the internet to the ALB like any other. The ALB decrypts it so it can pass the content to WAF.
    2. Step 2 The SQLi rule inspects the query string (after text transformations such as URL decode) and matches a SQL injection pattern.
    3. Step 3 Block is a terminating action: rules with a higher priority number do not run.
    4. Step 4 The target spends no CPU on this request. The WAF log records terminatingRuleId so you can look it up later. You can replace the 403 with a custom response.

    Lesson: when a rule matches with Block, the request stops at the ALB. The app behind it never sees that request.

    Case B · WAF on CloudFront, but the ALB is still public

    WAF is attached to CloudFront; the ALB behind it has no WAF and its security group allows 0.0.0.0/0. The attacker finds the ALB's DNS name (from logs, historical DNS, TLS certificates). (Illustrative scenario.)

    Predict before you run it: can the attacker avoid WAF?

    Yes. WAF sits on CloudFront, so a request sent straight to the ALB never passes through that Web ACL.

    Case B: the attacker calls the ALB directly and skips the WAF on CloudFront

    Main path

    1. Client

    2. CloudFront + WAF

    3. ALB

    4. App

    The request passes through the Web ACL at the edge.

    Bypass

    1. Attacker

    2. Public ALB DNS

    3. App

    It does not go through CloudFront: the edge Web ACL never inspects this request.

    1. Step 1 The main path works: a malicious request through the CloudFront domain is blocked by the global Web ACL.
    2. Step 2 This is the branch point. The ALB has public DNS and a security group open to every IP, so the request goes straight in without passing CloudFront.
    3. Step 3 The ALB has no Web ACL, so nothing inspects the request. Every rule written on CloudFront has no effect on this path.
    4. Step 4 The fix: allow only the com.amazonaws.global.cloudfront.origin-facing prefix list in the ALB's security group. Add a secret header sent by CloudFront and a listener rule that forwards only when the header is present. Or use CloudFront VPC Origins with an internal ALB.

    Lesson: WAF only protects the path through the resource it is attached to. To block everything, you have to close the other paths.

    Pair 2 · You need an NLB: the right way and the wrong way

    Source: Restrict access to an ALB origin.

    Case C · Static NLB IPs and WAF as well

    A partner requires a fixed IP allowlist, so you must use an NLB with Elastic IPs. The security team requires WAF. The solution: the NLB's target group has target type alb. (Illustrative scenario.)

    Predict before you run it: where in this chain does WAF attach?

    On the ALB. The NLB only forwards TCP; the ALB behind it decodes HTTP, so WAF can inspect it.

    Case C: the NLB forwards TCP to an ALB, and WAF on the ALB inspects the request

    Keep static IPs, add an L7 layer

    1. Partner

    2. NLB: TCP

    3. ALB + WAF

    4. Pod

    The Web ACL is attached to the ALB, not the NLB.

    1. Step 1 The NLB works at layer 4: it keeps static IPs and forwards TCP connections. It does not read HTTP content.
    2. Step 2 The NLB's target group registers an ALB directly. The ALB terminates TLS here.
    3. Step 3 From here the chain is the same as in the mechanism section: WAF evaluates rules by priority on the decrypted request.
    4. Step 4 The result: the NLB's static IPs and WAF's L7 filtering. The trade-off is paying for two load balancers and an extra network hop.

    Lesson: to have both an NLB and WAF, put an ALB with WAF behind the NLB.

    Source: ALB as an NLB target.

    Case D · Trying to attach a Web ACL straight to an NLB

    An EKS Service uses type: LoadBalancer and gets an NLB with TLS passthrough. The engineer tries associate-web-acl with the NLB's ARN. (Illustrative scenario.)

    Predict before you run it: is a SQLi payload sent through the NLB blocked?

    No. A Web ACL cannot attach to an NLB, and the NLB does not read HTTP, so the payload goes straight to the app.

    Case D: WAF cannot attach to the NLB, so the payload goes straight to the target

    No WAF on the path

    1. Attacker

    2. NLB: TLS passthrough

    3. Pod

    Associating a Web ACL with an NLB is not supported. You need an ALB for HTTP filtering.

    1. Step 1 With TLS passthrough, the NLB only sees encrypted bytes. There are no headers or URIs to inspect.
    2. Step 2 The NLB is not on the list of resources WAF supports. The associate-web-acl call fails, so no L7 layer is added.
    3. Step 3 The pod decrypts and processes the payload. The only protection left is the app's own code.
    4. Step 4 If you need HTTP filtering: switch to an Ingress ALB, or NLB → ALB as in case C. If you only need L3/L4 protection: use security groups for the NLB, Shield Advanced, AWS Network Firewall.

    Lesson: NLB, GWLB and Classic LB cannot have WAF attached. You have to change the architecture; there is no setting to turn on.

    Pair 3 · The ALB body limit, and substitutes when WAF cannot attach

    Case E · The payload sits past the first 8 KB of the body

    An API uploads 20 KB of JSON through an ALB. XSS/SQLi rules inspect the body with oversize handling set to Continue. The malicious payload sits at byte 12,000. (Illustrative scenario.)

    Predict before you run it: does WAF see the payload at byte 12,000?

    No. With an ALB, WAF only receives the first 8 KB (8,192 bytes). The limit is fixed and cannot be raised.

    Case E: a body larger than 8 KB on an ALB, and the later payload slips past WAF

    Body over the limit

    1. 20 KB body

    2. ALB + WAF: 8 KB

    3. App: full body

    With Continue and no other rule blocking, a payload outside the inspected part can reach the app.

    1. Step 1 Large bodies are normal for upload APIs or GraphQL. The malicious part is placed at the end of the body.
    2. Step 2 The body inspection limit for ALB and AppSync is fixed at 8 KB. CloudFront, API Gateway, Cognito, App Runner and Verified Access default to 16 KB and can go up to 64 KB.
    3. Step 3 Oversize handling = Continue means only the visible part is inspected. The part past the limit is not inspected by this rule. If no other rule blocks, the whole request still reaches the app.
    4. Step 4 Set Match in a rule whose action is Block to block bodies over the limit; Match on its own is not a blocking action. Or add a size constraint that blocks bodies over 8 KB on paths that need no upload. For deeper inspection, put CloudFront (up to 64 KB) in front, and still validate in the app.

    Lesson: on an ALB, WAF only sees the first 8 KB of the body. For the rest, you choose Match combined with a Block action, or Continue to inspect only the visible part.

    Source: Oversize handling and actions.

    Case F · API Gateway HTTP API: put CloudFront with WAF in front

    The backend uses an API Gateway HTTP API (not a REST API) with Lambda. An HTTP API cannot have a Web ACL attached, so you put CloudFront with WAF in front. (Illustrative scenario.)

    Predict before you run it: which region must the CloudFront Web ACL be created in?

    us-east-1, with scope CLOUDFRONT, even if the HTTP API lives in another region.

    Case F: CloudFront with WAF in front of an API Gateway HTTP API

    Blocked at the edge

    1. Client

    2. CloudFront + WAF

    3. HTTP API: authorizer

    4. Lambda

    The origin must actively check a secret header; CloudFront does not lock the API endpoint by itself.

    1. Step 1 The API's DNS points to CloudFront, not to the execute-api endpoint.
    2. Step 2 A CLOUDFRONT-scope Web ACL (created in us-east-1) runs at the edge. Bad requests are blocked before they reach the region.
    3. Step 3 CloudFront adds a custom origin header. The execute-api endpoint is still public, so this header is how you recognise a request that came through CloudFront.
    4. Step 4 Configure a Lambda authorizer or backend logic that checks the secret header and rejects requests where it is missing or wrong. Adding the header in CloudFront alone does not stop direct calls to execute-api. Do not write the secret value to logs; rotate it when needed. Alternatively, move to a REST API to attach WAF directly.

    Lesson: if a resource cannot have WAF attached, put CloudFront with WAF in front, then close direct access to the origin.

    Source: HTTP API Lambda authorizers.

    In front, behind: architecture patterns

    PatternChainUse whenRemember
    Single ALBInternet → ALB[WAF] → appSimple regional app8 KB body
    Edge + ALBCloudFront[WAF] → ALB → appPublic app, users in many placesLock the ALB to traffic from CloudFront only (case B). You can add WAF on the ALB too
    NLB + ALBNLB → ALB[WAF] → appStatic IPs, PrivateLinkCosts 2 load balancers (case C)
    Global AcceleratorGA → ALB[WAF] → appAnycast IPs, cross-region failoverGA cannot have WAF attached
    Origin without WAF supportCloudFront[WAF] → S3/Lambda URL/HTTP APIStatic sites, serverlessOAC or a secret header (case F)

    When to use WAF and when not to

    Use WAF

    • OWASP-style flaws: SQLi, XSS, path traversal, Log4j (managed rules).
    • Brute force, spam: rate-based rules for /login, /otp.
    • Bots, scraping, credential stuffing: Bot Control, ATP, ACFP, CAPTCHA, Challenge.
    • Geo, IP reputation: block countries, bad IPs, VPN/Tor.
    • Virtual patching: temporarily block a CVE while waiting for a code fix.

    Use another service

    • TCP/UDP traffic: Network Firewall, Shield, security groups.
    • L3/L4 DDoS: Shield Advanced.
    • Egress filtering: Network Firewall, DNS Firewall.
    • Authentication, authorization: Cognito, IAM, logic in the app.
    • Large bodies on an ALB: validate in the app or use CloudFront's 64 KB.

    Common myths

    MythReality
    Turning on WAF for the NLB is enoughAn NLB cannot have a Web ACL attached; put an ALB behind it if you need HTTP filtering
    WAF on CloudFront means the origin is safeYou must close direct access to the origin
    WAF reads the whole bodyALB/AppSync are limited to 8 KB; supported resources can raise the limit to at most 64 KB
    WAF stops every DDoSL3/L4 floods need a suitable layer such as Shield
    X-Forwarded-For is always the real IPYou must define the trusted proxy chain and how the header is built

    Config examples

    AWS CLI · Attach a Web ACL to an ALB

    The ARNs are examples. A Web ACL for an ALB uses REGIONAL scope, in the same region as the ALB. Not tested.

    aws wafv2 associate-web-acl \
      --web-acl-arn arn:aws:wafv2:ap-southeast-1:111122223333:regional/webacl/shop-acl/abcd1234 \
      --resource-arn arn:aws:elasticloadbalancing:ap-southeast-1:111122223333:loadbalancer/app/shop-alb/50dc6c495c0c9188
     
    # Keep fail-closed (the default): if WAF does not respond, the ALB does not forward the request
    aws elbv2 modify-load-balancer-attributes \
      --load-balancer-arn arn:aws:elasticloadbalancing:ap-southeast-1:111122223333:loadbalancer/app/shop-alb/50dc6c495c0c9188 \
      --attributes Key=waf.fail_open.enabled,Value=false

    EKS Ingress · Attach WAF through an annotation

    The AWS Load Balancer Controller creates the ALB and attaches the Web ACL. Values are examples.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: shop
      annotations:
        alb.ingress.kubernetes.io/scheme: internet-facing
        alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:ap-southeast-1:111122223333:regional/webacl/shop-acl/abcd1234
    spec:
      ingressClassName: alb
      rules:
        - http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: shop
                    port:
                      number: 80

    JSON · Rate limit /login by forwarded IP

    A rule for a Web ACL on an ALB behind CloudFront. The threshold is an example; check the schema in the WAF docs before using it.

    {
      "Name": "login-rate", "Priority": 1,
      "Action": { "Block": {} },
      "Statement": { "RateBasedStatement": {
        "Limit": 100, "EvaluationWindowSec": 300,
        "AggregateKeyType": "FORWARDED_IP",
        "ForwardedIPConfig": { "HeaderName": "X-Forwarded-For", "FallbackBehavior": "MATCH" },
        "ScopeDownStatement": { "ByteMatchStatement": {
          "SearchString": "/login", "PositionalConstraint": "STARTS_WITH",
          "FieldToMatch": { "UriPath": {} },
          "TextTransformations": [{ "Priority": 0, "Type": "NONE" }] } } } },
      "VisibilityConfig": { "SampledRequestsEnabled": true,
        "CloudWatchMetricsEnabled": true, "MetricName": "login-rate" }
    }

    Self check

    Recall: name the resources that can have WAF attached, and three load balancer types that cannot.

    Can attach: CloudFront, ALB, API Gateway REST API, AppSync GraphQL, Cognito user pool, App Runner, Verified Access, Amplify, Bedrock AgentCore Gateway. Cannot attach: NLB, GWLB, Classic LB. To get WAF, put an ALB or CloudFront in the right place in the chain.

    Question 1: static IPs and SQLi

    A partner only allowlists static IPs, so the system uses an NLB with Elastic IPs. The security team requires blocking SQLi with managed rules. What do you do?

    1. Attach the Web ACL directly to the NLB.
    2. Register an ALB as the NLB's target and attach WAF to the ALB.
    3. Add a security group to the NLB that blocks port 443.
    4. Turn on Shield Advanced for the Elastic IPs.

    Answer yourself before reading the explanation

    • WAF on the NLB — Not quite. The NLB is not on the supported resource list, and it does not read HTTP.
    • NLB → ALB[WAF] — Correct. The NLB keeps the static IPs, and the ALB decodes HTTP so WAF can run managed rules (case C).
    • Security group — Not quite. Security groups filter by IP and port and cannot recognise SQLi. Blocking 443 also breaks the service.
    • Shield only — Not quite. Shield protects against DDoS; it does not run layer 7 SQLi rules for the NLB.

    Question 2: the bypass into the ALB

    The Web ACL on CloudFront blocks well. But app logs show malicious requests whose Host is the ALB's DNS name (*.elb.amazonaws.com). Where do you fix it?

    1. Add another SQLi rule to the CloudFront Web ACL.
    2. Lock the ALB: a security group that allows only CloudFront's prefix list, a secret header, or VPC Origins.
    3. Raise CloudFront body inspection to 64 KB.
    4. Turn on waf.fail_open.enabled on the ALB.

    Answer yourself before reading the explanation

    • Add a CF rule — Not quite. These requests do not pass through CloudFront, so rules there never run.
    • Lock the origin — Correct. This is the bypass from case B. Once direct calls are blocked, every request has to pass through WAF.
    • Raise the body limit — Not quite. Unrelated. The requests do not pass through CloudFront.
    • Fail open — Not quite. The ALB has no WAF; fail open would only loosen things further when WAF fails.

    Question 3: protecting an HTTP API

    A new backend uses an API Gateway HTTP API to keep costs low. It needs rate limiting and bot blocking. Which approach is right?

    1. associate-web-acl directly with the HTTP API stage.
    2. Attach WAF to the Lambda function behind it.
    3. Put CloudFront with WAF in front and check a secret header at the origin; or move to a REST API.
    4. Use Network Firewall with WAF's managed SQLi rule.

    Answer yourself before reading the explanation

    • Attach directly — Not quite. Only REST APIs are supported; an HTTP API cannot have a Web ACL attached.
    • WAF on Lambda — Not quite. Lambda is not a resource WAF can attach to.
    • CloudFront in front — Correct. CloudFront is a WAF-supported resource and stands in for the HTTP API (case F).
    • Network Firewall — Not quite. Network Firewall does not use WAF managed rule groups, and has no Bot Control or CAPTCHA.

    Question 4: body over the limit

    An API uploads 30 KB of JSON through an ALB. A pentest puts a payload at the end of the body and it gets past WAF. What is the best first step?

    1. Raise the ALB body inspection limit to 64 KB.
    2. Change the body rule's oversize handling to Match (or block large bodies on paths that don't need them), and validate in the app.
    3. Add a rate-based rule.
    4. Switch to an NLB.

    Answer yourself before reading the explanation

    • Raise the ALB limit — Not quite. On an ALB the limit is fixed at 8 KB; there is no option to raise it.
    • Match + validate — Correct. With a Block action, oversize Match treats a body over 8 KB as a match and blocks the request (case E). If a path needs large bodies, put CloudFront's 64 KB in front and validate in the app.
    • Rate-based — Not quite. A rate limit counts requests; it does not let WAF read the truncated part of the body.
    • Switch to NLB — Not quite. An NLB has no WAF, so you lose the L7 layer entirely.

    Question 5: UDP flood

    A multiplayer game server uses UDP through an NLB and is being flooded. Which service fits?

    1. AWS WAF with a rate-based rule.
    2. Shield Advanced (protecting the Elastic IPs/NLB) combined with network filtering.
    3. CloudFront in front of the NLB.
    4. A Cognito user pool.

    Answer yourself before reading the explanation

    • WAF — Not quite. UDP is not HTTP, and WAF cannot attach to an NLB.
    • Shield Advanced — Correct. L3/L4 floods are Shield's job. You can add Network Firewall, security groups and NACLs.
    • CloudFront — Not quite. CloudFront serves HTTP(S)/WebSocket; it does not proxy a game's UDP.
    • Cognito — Not quite. Cognito is a user authentication service; it does not filter network traffic.

    Transfer exercise: your own architecture (try it before opening)

    Brief: a system has (1) a Next.js web app on EKS, exposed with a Service of type: LoadBalancer; (2) a mobile API on an API Gateway HTTP API; (3) product images on a public S3 bucket; (4) an admin portal behind an internal ALB. Place WAF for each part, and point out which paths still get through.

    Answer criteria: (1) If the LoadBalancer Service provisions an NLB as in the brief, switch to an Ingress ALB with the wafv2-acl-arn annotation; you can add CloudFront in front and lock the ALB. (2) CloudFront+WAF in front of the HTTP API with a secret header check, or move to a REST API. (3) Drop the public bucket and use CloudFront+OAC+WAF. (4) The internal ALB can still have WAF if needed, combined with a security group that allows only VPN/Verified Access. Paths to check for leaks: the execute-api endpoint, the ALB's DNS name, direct S3 URLs.

    Core terms

    TermMeaning
    Web ACL (protection pack)A set of rules with priorities and a default action. The unit attached to a resource.
    ScopeREGIONAL (ALB, API GW…) or CLOUDFRONT (created in us-east-1).
    WCUThe unit of a rule's compute cost. Each Web ACL has at most 5,000 WCU; anything above 1,500 costs extra.
    Managed rule groupA rule set maintained by AWS or a vendor: Core rule set, SQLi, Known bad inputs, IP reputation, Bot Control, ATP, ACFP.
    Rate-based ruleCounts requests per key (IP, forwarded IP, header…) within a time window and applies the action above a threshold.
    LabelA tag a rule adds to a request, for later rules or the app to act on.
    Oversize handlingHow the part of a request past the inspection limit is handled: Continue, Match, No match.
    Firewall ManagerCentral management of WAF, Shield and Network Firewall across accounts in Organizations.

    Source: WCU, Rate-based rules.

    Closing and golden rules

    WAF is not a network hop of its own; it attaches to a resource.

    Within ELB, only the ALB can have it attached. NLB, GWLB and Classic LB need an architecture change.

    If a request has a path into the app that does not pass a resource with WAF attached, WAF has no effect on that request.

    If it is not HTTP, use Shield, Network Firewall and security groups.

    Layer 7 only·Attach to the right resource·Close the bypass

    Source: AWS WAF Developer Guide — supported resources · Body inspection limits · ALB attributes (waf.fail_open.enabled, Local Zone, Outpost) · ALB as an NLB target. Checked on 2026-10-05.

    Written by

    Hieu Vu

    Software engineer writing about cloud infrastructure, DevOps and reliable systems.