Create and manage Azure Front Door Web Application Firewall custom rules to block, allow, or log traffic, monitor events, and prevent backend bypass.
WAF custom rules let you extend the managed/default rule set with targeted, environment-specific protections. Where the managed rule set provides baseline defenses for common web threats, custom rules enable fast, surgical responses to patterns unique to your application — for example blocking an IP range, filtering a country, or applying special header checks.
Custom rules are administrator-defined match conditions evaluated before the managed/default rule set. Use them to Allow, Block, or Log specific traffic patterns immediately at the edge (Front Door), preventing unwanted requests from reaching your backend.Key characteristics:
Evaluated before the managed/default rule set.
Priority is numeric; a lower number executes earlier (priority = 1 runs before priority = 2).
Custom rules provide fast, targeted responses to threats (for example, blocking a specific IP range or country) without waiting for updates to the managed rule set.
Example scenario: Block all requests from the United States
Goal: Prevent any traffic originating from the United States from reaching your app.Steps (Azure portal summary):
Open the Front Door WAF policy.
Navigate to Custom Rules > Add custom rule.
Name the rule (e.g., deny-US). Set Status = Enabled, Rule type = Match, Priority = 1.
Add a condition:
Match variable: GeoLocation (country)
Operator: Equals
Value: United States
Set Action = Block (or Log if you want to observe first).
Save. Because the rule has a low priority number it will be evaluated before managed rules.
Testing:
Use a VPN endpoint located in the country you want to test (e.g., United States) and try requests to your application. Requests from that country should be blocked if configured correctly.
Monitor WAF logs in Log Analytics to validate hits and check for false positives before enforcing block actions at scale.
Security caveat — direct backend endpoints can bypass WAF
WAF rules applied to Front Door protect traffic that flows through Front Door. If your backend has an exposed platform hostname (for example, webapp.azurewebsites.net for an Azure App Service), clients can bypass Front Door/WAF by calling that direct URL.
If your backend is accessible via a public platform URL (for example, webapp.azurewebsites.net), attackers can bypass Front Door/WAF by calling that address directly. To prevent this, consider restricting direct access using Private Endpoints, access restrictions (IP restrictions or service tags), or ensuring the backend only accepts traffic routed through Front Door.
Example of a direct-access URL that bypasses Front Door (when present):