Azure App Gateway WAF_v2 Custom Rule evaluation of RequestUri fails to limit allowed paths

Marius Shekow 25 Reputation points
2025-07-16T09:53:04.4166667+00:00

I have an Azure App Gateway (AppGW) whose public listener I configured with a Path-based routing rule. That Routing Rule has a default backend configured (which is required, even though I would prefer not to), and several routes, e.g.

  • Path "/a/*" sends traffic to backend pool A
  • Path "/b/*" sends traffic to backend pool B

What I would like to implement is that AppGW denies incoming HTTP calls (with status code 403) made to any paths other than "/a/" or "/b/" (e.g. calls made to "/foo").

I thought that I could use a WAF policy for this, but this does not seem to be possible.

What I've tried, but it does not do what I want:

I created a WAF Policy with a custom rule:

  • it is a "Match" type rule for a String
  • the Match variable is set to RequestUri
  • the "is not" operator is enabled
  • the Operator is set to "Begins with"
  • For the Match Values, I provide the list of paths, e.g. "/a/" and "/b/"
  • Action is "Deny traffic"

However, the problem is that the WAF engine has a weird behavior when evaluating the custom rule: For instance, if I make an HTTP call to "/a/xyz" (which should not be blocked), instead of matching the original (full) request URI, the WAF engine only evaluates "/xyz" (according to the AGWFirewallLogs LAW table entries), and then blocks the request. So, it seems that only the Uri part that "remains" within the specific Path rule is evaluated.

For now, my workaround is to configure the Path-based routing rule with a default backend that is actually empty, so AppGW responds to calls made to "/foo" with 502, but I would have preferred to do this via a WAF policy.

Any ideas on how this could be improved?

Azure Web Application Firewall
{count} votes

Accepted answer
  1. G Sree Vidya 4,005 Reputation points Microsoft External Staff Moderator
    2025-07-23T23:33:51.6066667+00:00

    Hello Marius Shekow

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution.

    Issue: Azure App Gateway WAF_v2 Custom Rule evaluation of RequestUri fails to limit allowed paths

    Solution:

    • In the URL Path map, create a fallback path rule (placed last) for /* and make sure to assign a valid (non-empty) backend pool, e.g., use the same one that I also use for /a/*
    • Create a WAF policy and associate it with that just-created fallback path rule, and configure a Custom Rule that matches the RequestUri via Regex .*, denying all traffic.

    Please click "Accept" the answer as original posters help the community find answers faster by identifying the correct answer.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.