Aws

WAF를 이용하여 POST Body에 특정 Key만 허용하기

wngnl-dev 2024. 8. 10. 15:31

 

{
  "Name": "CheckForLengthKey",
  "Priority": 1,
  "Action": {
    "Block": {
      "CustomResponse": {
        "ResponseCode": 403
      }
    }
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "CheckForLengthKey"
  },
  "Statement": {
    "AndStatement": {
      "Statements": [
        {
          "ByteMatchStatement": {
            "FieldToMatch": {
              "UriPath": {}
            },
            "PositionalConstraint": "EXACTLY",
            "SearchString": "/v1/token",
            "TextTransformations": [
              {
                "Type": "NONE",
                "Priority": 0
              }
            ]
          }
        },
        {
          "ByteMatchStatement": {
            "FieldToMatch": {
              "Method": {}
            },
            "PositionalConstraint": "EXACTLY",
            "SearchString": "POST",
            "TextTransformations": [
              {
                "Type": "NONE",
                "Priority": 0
              }
            ]
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "ByteMatchStatement": {
                "FieldToMatch": {
                  "JsonBody": {
                    "MatchScope": "KEY",
                    "MatchPattern": {
                      "All": {}
                    },
                    "OversizeHandling": "CONTINUE"
                  }
                },
                "PositionalConstraint": "EXACTLY",
                "SearchString": "length",
                "TextTransformations": [
                  {
                    "Type": "NONE",
                    "Priority": 0
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}