Modifying AWS WAF Configuration in Terraform to Allow requestBodySize Up to 32kb

169 views Asked by At

I have an AWS WAF setup that I configured using Terraform. Currently, I'm facing an issue where it blocks any request with a requestBodySize greater than 16kb. I'm looking to adjust this so it allows requestBodySizes of up to 32kb.

Following is my terraform code

rule {
    name     = "AWS-AWSManagedRulesCommonRuleSet"
    priority = 2
    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesCommonRuleSet"
        vendor_name = "AWS"
      }
    }
    override_action {
      none {}
    }
    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWS-AWSManagedRulesCommonRuleSet"
      sampled_requests_enabled   = true
    }
  }

I tried to add a following rule to override the size limitation. But it didn't work.It is still allowing requestBodySize upto 16kb only. Logs from the cloud watch

requestBodySize   301984
requestBodySizeInspectedByWAF  16384
 rule {
    name     = "CustomSizeConstraintRule"
    priority = 0  # Set priority to ensure correct rule order
    action {
      allow {}  # Action to take if the rule matches
    }
    statement {
      size_constraint_statement {
        comparison_operator = "LE"  # Less than or equal to
        size                = 32768  # 32 KB in bytes
        field_to_match {
          body {}  # Match based on the body of the request
        }
        text_transformation {
          priority = 0
          type     = "NONE"
        }
      }
    }
    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "CustomSizeConstraintRule"
      sampled_requests_enabled   = true
    }
  }

Does anyone know a solution to this?

0

There are 0 answers