I have an App GW WAF v2 where I need to set up a custom rule to check for the presence of a Request Header. I couldn't get it to work. So next I set up a very simple check.
"customRules":[{
"name":"blockTEST",
"priority":1,
"ruleType":"MatchRule",
"matchConditions":
[{"matchVariables":
[{"variableName":"RequestHeaders","selector":"My-Header"}],
"operator":"Contains",
"negationConditon":false,
"matchValues":["evil"],
"transforms":["Lowercase"]
}],
"action":"Block"
}]
I am submitting a request with "My-Header" as a header and with the value of "evil". But it doesn't block it. Have also tried various comparison operators including Starts With, Contains, Equals, ... but nothing works
So far the only custom rule that works is when I set a Block based on IP. But thats not what I want.
Any suggestions? Jake.
I tried to reproduce the same in my environment and got the results successfully like below:
I created application gateway WAF v2 and created a sample custom rule like below:
When I check the request of my header it blocks succcessfully like below:
If rule are not work properly try to check the WAF policy is linked to the appropriate listener of your Application Gateway like below:
References:
Application Gateway WAF v2 Custom Rules by Yannic Graber
Azure Application Firewall (WAF) v2 custom rules on Application Gateway | Microsoft Learn