How do I allow requests from an oversized request body to pass through WAF?

0

Hello, In the EC2 instance, there is an image processing API, and I associate a WAF on ALB, then configured the following rule in the WAF:

const awsManagedRulesCommonRuleSet: wafv2.CfnWebACL.RuleProperty = {
  name: `AWS-AWSManagedRulesCommonRuleSet`,
  priority: 0,
  overrideAction: { none: {} },
  visibilityConfig: {
    metricName: `MetricForAMRCRS`,
    sampledRequestsEnabled: true,
    cloudWatchMetricsEnabled: true,
  },
  statement: {
    managedRuleGroupStatement: {
      vendorName: 'AWS',
      name: 'AWSManagedRulesCommonRuleSet',
      excludedRules: [
        { 
          name: 'SizeRestrictions_BODY',
        },
        {
          name: 'NoUserAgent_HEADER',
        },
      ],
    },
  },
};
new wafv2.CfnWebACL(this, 'ServerWebACLs', {
  name: 'ServerALB-WebACLs',
  scope: 'REGIONAL',
  defaultAction: { allow: {} },
  visibilityConfig: {
    metricName: 'ServerALB-WebACLs',
    sampledRequestsEnabled: true,
    cloudWatchMetricsEnabled: true,
  },
  rules: [
    awsManagedRulesCommonRuleSet,
    // and some other rule,such as IPRule,SqlRule...
  ],
});

The request body of the API contains image data, when I call that API through Cloudfront, I keep getting a 403 error. If I use an API that doesn't contain image data, it can be called successfully. Why is that? Am I not configured correctly?

2개 답변
1

Hi,

It could be useful to configure AWS WAF for sending web ACL traffic logs to CloudWatch and identify the rules that the request matched.

profile picture
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
  • Thanks for your reply, from the traffic overview of the WAF, the blocked request shows that the attacktype is GenericLFI. but the api just adds an image file to form-data.

  • Now that you know the cause, it should be easier to find the solution.

    For example, the following StackOverflow response suggests to check the image metadata, it may help you.

1

You've included the awsManagedRulesCommonRuleSet - looking at the documentation it includes a rule that is defined as follows:

SizeRestrictions_BODY 	
Inspects for request bodies that are over 8 KB (8,192 bytes).
Rule action: Block

So perhaps don't use that rule set?

profile pictureAWS
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
  • Thanks for your reply, but I'm exclude the rule in my code, not include.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠