Review AWS WAF protection for API Gateway

Apply required web request filtering to REST API stages and check its effect on legitimate requests.

Description

To apply AWS WAF rules to an API Gateway REST API, associate a web ACL with the stage that needs protection.

Potential impact

Missing filters can send unwanted traffic to the backend. Overly broad blocking rules can reject legitimate customers.

Remediation

Use a REGIONAL web ACL in the same Region as the stage. Test managed or custom rules with Count before enabling blocking. Verify the stage association and review request logs. Keep caller authentication, permission checks and application patches in place.

Examples

Supply the REST API, deployment and web ACL. Set ApiWebAclArn to that ACL’s ARN and configure its rules and logging separately.

Before

yaml
Resources:
  ProdStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: Prod
      RestApiId: !Ref MyRestApi
      DeploymentId: !Ref ApiDeployment

After

yaml
Resources:
  ProdStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: Prod
      RestApiId: !Ref MyRestApi
      DeploymentId: !Ref ApiDeployment

  ProdStageWebAclAssociation:
    Type: AWS::WAFv2::WebACLAssociation
    Properties:
      WebACLArn: !Ref ApiWebAclArn
      ResourceArn: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}::/restapis/${MyRestApi}/stages/${ProdStage}

The second template uses MyRestApi and ProdStage to build the stage ARN and attach the web ACL to Prod in the current Region.

References