Implementing Azure Web Application Firewall
This lesson explains how Azure WAF works on Application Gateway and Front Door, and how to tune it.
Learning outcomes
After completing this lesson, you will be able to:
- Compare the WAF on each service.
- Explain Detection and Prevention modes.
- Explain anomaly scoring.
- Describe how to handle a false positive.
What a WAF does
An NSG sees addresses and ports, so it treats a request carrying SQL injection as ordinary HTTPS. A web application firewall (WAF) understands HTTP and examines headers, URLs and bodies for attack patterns, such as SQL injection and cross-site scripting. Azure WAF is not a separate appliance. It is a feature that is attached to one of the following services.
Policies and modes
A WAF policy is a separate resource that holds settings and rules. It has two modes.
| Mode | Behaviour | Use |
|---|---|---|
| Detection | Logs matches and does not block | During tuning |
| Prevention | Blocks matching requests, with a 403 response | In production, after tuning |
The usual approach is to start in Detection, review what would be blocked, add exclusions for false positives, and then move to Prevention. Staying in Detection indefinitely is a common failure, and an audit would find that the WAF protects nothing. On Application Gateway, association of a policy needs WAF_v2. A policy can apply to a gateway, a listener or a route path. On Front Door, policies can attach at profile, domain or route level, with a route taking precedence over a domain, and a domain over a profile.
WAF modes and placement
Managed rules and scoring
Managed rule sets, such as the Default Rule Set, are maintained by Microsoft, and they cover the OWASP Top 10 categories. Application Gateway also supports older Core Rule Sets (CRS 3.2, 3.1 and 3.0). Anomaly scoring is the default on Application Gateway: each matching rule adds a score according to its severity, with Critical adding 5, Error 4, Warning 3 and Notice 2. A request is blocked in Prevention mode if its total reaches 5.
This means that a single Critical match blocks a request, whereas several minor matches can add up to a block. On Front Door, Default Rule Set 2.0 and later use anomaly scoring too. Bot Manager rules do not use it.
The following diagram adds up the scores for three requests.

Anomaly scores
Custom rules
Custom rules handle needs that managed rules do not, and they are evaluated before managed rules. They can match on IP address, geographic location, headers, query strings and other conditions, with actions of Allow, Block and Log, plus Redirect and Anomaly score on Front Door. Rate limit rules restrict how many requests a client can make within one or five minutes on Front Door. Rules are evaluated by priority.
A custom Allow rule ends evaluation, so a careless allow can bypass managed protections. On Front Door, however, the HTTP DDoS rule set is evaluated before custom rules, and a custom Allow does not bypass it.
Tune narrowly
If a false positive blocks a legitimate request, the first option is an exclusion for that field, not disabling a whole rule set or switching the policy to Detection.
Custom rules and bots
Bot protection
Bots generate a large share of traffic, and they range from helpful search crawlers to credential-stuffing tools. The Bot Manager rule set sorts them into Bad, Good and Unknown. On Application Gateway, bad bots are blocked by default, verified search engine crawlers are allowed, unknown search engine crawlers are blocked and unknown bots are logged. On Front Door, Bot Manager needs the Premium tier, and it can use a JavaScript challenge. An IP Reputation rule set can also block addresses that are known to be malicious.
Logging and bypass prevention
WAF logs go to a Log Analytics workspace through diagnostic settings, and they show the rule, the matched field and the action. These logs are the source for tuning, and for Microsoft Sentinel detection.
A WAF only protects traffic that passes through it, so make sure that the back end cannot be reached directly. Restrict the origin to Application Gateway's subnet or to Front Door's traffic, or use Private Link. Note that Front Door classic retires on 31 March 2027, so new designs should use Standard or Premium.
A false positive
After a WAF on Application Gateway was switched to Prevention mode, customers are blocked when they submit a form with a long comment field, because a rule treats the text as SQL. The rest of the protection must remain in place. What should you do?
Use WAF logs to identify the rule and the field. Add an exclusion for that specific request attribute, for example the comment field, so that the rule no longer inspects it, and keep the policy in Prevention mode.
Switching to Detection would remove all protection. Disabling the whole rule group would weaken protection for every field. A custom Allow rule for all form submissions would bypass the managed rules entirely for those requests.
A request matches one Warning rule and one Error rule on Application Gateway. Is it blocked in Prevention mode?
Show answer
Yes. The scores of 3 and 4 add up to 7, which passes the threshold of 5.
Exam Tips
Remember for the exam
- Start in Detection, tune, then move to Prevention.
- Custom rules run before managed rules.
- Bot Manager on Front Door needs Premium.
- A score of 5 or more blocks in Prevention mode on Application Gateway.