AWS WAFv2 determine header order

0

I am wondering if it is possible to determine the header key order in the request then use this value in rules?

For example the header object would contain the following

HeadHead
httpRequest.headers.0.nameHost
httpRequest.headers.0.valueapi.test.com
httpRequest.headers.1.nameuser-agent
httpRequest.headers.1.valueMozilla/5.0 (Linux; Android 10; SM-A217F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36

I want to check httpRequest.headers.1.name to see if this was user-agent

HieuVu
질문됨 2년 전424회 조회
2개 답변
0

Hello HieuVu,

Well, the order your seeing is a interpret format of the request for log view (ie., For Reading purpose and Filtering purpose in CW or Athena).

Thus, at any point of time WAF only sees Key:Value (Ie., User-Agent:Mozilla/5.0...) header components NOT the order of the HTTP components.

https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statement-fields.html

Regards, CK

profile pictureAWS
답변함 2년 전
  • Hi Chethan,

    I understand that it is an interpret format, my questions is, if it is possible to determine the order that headers are in the headers, so either see what the second header is or determining what order did user-agent get sent in.

0

Hello HieuVu,

AWS WAF now supports Header Order match statement for request inspection

https://aws.amazon.com/tw/about-aws/whats-new/2023/06/aws-waf-header-order-match-statement-request-inspection/

AWS WAF separates the header names in the string using colons and no added spaces, for example

host:user-agent:accept:authorization:referer

In your use case, you can configure WAF rule like this:

host:user-agent with PositionalConstraint STARTS_WITH

Here is example WAF rule JSON

{
  "Name": "testheaderorder",
  "Priority": 0,
  "Action": {
    "Count": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "testheaderorder"
  },
  "Statement": {
    "ByteMatchStatement": {
      "FieldToMatch": {
        "HeaderOrder": {
          "OversizeHandling": "CONTINUE"
        }
      },
      "PositionalConstraint": "STARTS_WITH",
      "SearchString": "host:user-agent",
      "TextTransformations": [
        {
          "Type": "NONE",
          "Priority": 0
        }
      ]
    }
  }
}

To find more information regrading HeaderOrder , see:

HeaderOrder

https://docs.aws.amazon.com/waf/latest/APIReference/API_HeaderOrder.html

AWS Web Application Firewall (WAF): Header Order Match Statement | Amazon Web Services

https://www.youtube.com/watch?v=gZtGBhXlgIo

profile pictureAWS
Mark_W
답변함 9달 전

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

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

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

관련 콘텐츠