Azure WAF Custom Rule Samples and Use Cases

Published Jan 05 2021 06:43 AM 6,045 Views
Microsoft

Written in collaboration with @camilamartins 

 

This post will detail how to use Custom Rules on Azure WAF, including some examples of common use cases fulfilled by this rule type. Custom Rules provide a versatile way to build controls that fulfill security requirements and protect applications from attacks that are unique to your applications.

 

WAF Rule Types and Processing

Azure WAF currently offers 3 rule types, which are processed in the following order:

  1. Custom Rules – custom rules are processed first, and function according to the logic you select. This makes them very powerful as the first line of defense for web applications.
  2. Managed OWASP Rules – OWASP rulesets are based on the SpiderLabs Core Ruleset (CRS), and can detect common web attacks like SQL injection, cross-site scripting, and command injection. These rules cannot be modified, but the ruleset can be tuned by using exclusions and by modifying rule actions (a topic for another post).
  3. Managed Bot Rules – these rules identify potential bot activity by matching sources against our internal Threat Intelligence feeds. If traffic is coming from a known source of bot activity, the traffic can be blocked.

This post focuses on Custom Rules, but it is important to understand how the managed rulesets work. For more information on these, look for future blog posts here or consult the Azure WAF documentation.

 

Important Custom Rule Concepts

Custom Rules can be viewed and built using the Azure Portal by navigating to Web Application Firewall Policies (WAF), selecting your policy, and clicking on the Custom Rules blade. Creating a custom rule is as simple as clicking Add Custom Rule and entering a few required fields. However, there are some important concepts to understand before you create your own rules.

 

The most important thing to mention about Custom Rules is that they are terminating. This means that if the logic of the rule is matched, all other rules stop processing, including the lower priority (higher number) Custom Rules, and both OWASP and Bot managed rulesets. This is the case regardless of the action of the rule; even if traffic is allowed, no further rules are processed. This can have positive or negative implications.

 

The Allow action should be used sparingly in Custom Rules, because since the rule terminates, it means that all other inspection provided by WAF will be skipped. Understanding this, you can use Allow rules when the intent is to skip the other checks, such as in tuning situations. If certain requests tend to trigger false positives, you can use a Custom Rule to allow the traffic at a more granular level than it would be possible by using exclusions or disabling rules.

 

In most scenarios, it is best to use Custom Rules with the Deny action, as a terminating Deny rule is entirely expected and without unanticipated consequences. For instance, if you wanted to use a WAF Custom Rule to create an IP Address allow list, it is better to Deny traffic that is not from the IP addresses in the list rather than Allow traffic from those IPs. Using the Deny action avoids causing traffic allowed by this rule to bypass the OWASP and Bot rulesets.

 

Another concept to make use of in constructing effective Custom Rules is compound conditions. Rules can be created with a single condition, or you can add multiple conditions that must be satisfied to constitute a match. When adding multiple conditions, they are added as an AND statement, so all conditions must be met for the Action to take place. If you need to construct a rule with OR logic, it is best to create multiple rules with the same Action.

 

Custom Rule Example Templates and Use Cases

We have created 2 ARM templates, which will create both WAF Policy types, one for WAF on Application Gateway and one for WAF on Front Door. These policies are intended to give you a starting point for creating your own Custom Rules. To deploy, simply click the Deploy to Azure buttons from the repository, select a Resource Group, and create your policies.

 

These example policies must be modified to fit your requirements before associating with any Front Door or Application Gateway resources, and the following sections will provide guidance on how to do so.

 

Block Lists

Some customers have the requirement to block certain sources of traffic based on IP address or country of origin. In these scenarios, block lists can be used, which you must create and keep up to date. The examples included in the templates are GeoBlockList and IPBlockList. The behavior of these basic rules can be modified to add conditions if necessary. For example, you may want to block a certain part of a site from a geographic region, as pictured:

Anthony_Roman_1-1609857161165.png

 

Notice that there is a second condition in the "And if" box, which defines a specific request URI. This additional condition creates an AND expression, meaning that both the first condition about geolocation and the second condition about the request URI must be matched in order for the Deny action to trigger.

 

These block lists can be added manually via the Portal or managed programmatically using ARM, API, or CLI. One example of adding to a block list automatically using Azure Sentinel Playbooks can be found in a previous post.

 

Allow Lists

IP address or geographic restrictions can be accomplished effectively using allow lists. This method is preferable if you only do business in certain countries, or if you have an internal website you would like to be available only to trusted IP addresses, such as corporate IP blocks.

 

The following example shows the IPAllowList rule found in the template:

Anthony_Roman_2-1609857161169.png

 

Notice that the allow list uses the "Does not contain" operator. This allows our logic to use the Deny action to block only the traffic that does not originate from the trusted range. This means that the trusted IP addresses or ranges will continue to be inspected by the other applicable WAF rules. Using this approach, we can avoid creating a rule using the "Does contain" operation along with the Allow action, which would result in a rule termination scenario that would exempt the trusted traffic from further WAF inspection.

 

Controlling Allowed HTTP Methods

HTTP method enforcement can be done in a dynamic way using WAF Custom Rules. Consider the scenario where you have an API that should be available publicly for customers to GET and POST, but you want to reserve PUT and DELETE actions for traffic originating from trusted locations as an extra layer of security beyond authentication. The following modification of the MethodAllowList rule can be used to accomplish this.

Anthony_Roman_3-1609857161178.png

 

Blocking User Agents

Some of the OWASP managed rules will detect well known malicious user agents, but if you find the need to block a specific set, a Custom Rule is a way to accomplish this. Of course, user agent is not a difficult element for an attacker to change, but this type of rule can help deflect unsophisticated attackers. The logic of the UserAgentBlock rule is represented in the template pictured below.

Anthony_Roman_4-1609857161181.png

 

 

Rate Limiting with WAF for Front Door

WAF on Azure Front Door has the added capability of Custom Rules with a Rate Limit type, as distinct from Match type rules. Rate Limit rules will keep track of the number of requests from a particular IP address and block requests made after a threshold is reached.

 

These rules can be part of an effective layer 7 DDoS protection strategy. Azure DDoS Protection, both at the platform level (free) and using the Standard tier (paid) will protect against high volume attacks, but there are application attacks that do not necessarily rely on high volume. Some of these attacks can be mitigated by using source rate limiting in Custom Rules. The idea is that a legitimate user of a site will make a predictable number of requests to the site over a given time period, but an attacker trying to disrupt the site’s availability would likely make more requests. A threshold can be set to limit the volume of traffic to a particular path from a source, as pictured below.

Anthony_Roman_5-1609857161185.png

 

In the above rate limiting rule, 100 requests from the same IP address would be allowed within any 1 minute time period, but after the threshold is met, additional requests from that IP would be dropped for 1 minute. After the rate limiting period expires, traffic is allowed and the counter to 100 starts again.

 

Using WAF on Application Gateway to only Allow Traffic from your Front Door

A common architectural design is to use Azure Front Door to provide global load balancing and content distribution in front of Application Gateways hosted in 2 or more regions. NSGs can be used on the Application Gateway subnet to only allow traffic from the Front Door service, but the remaining security concern here is that Front Door is a shared service. You probably want to allow traffic only from your Front Door service specifically to prevent an attacker from setting up a “rogue” Front Door instance without WAF in order to circumvent inspection.

 

Fortunately, Front Door adds a header (X-Azure-FDID) to all traffic it processes, which identifies it as your instance of Front Door. Pictured below is a WAF Custom Rule, AllowFrontDoor in the template, that will only allow traffic that contains this specific header value. This guarantees that traffic sourcing from unapproved Front Door instances will not connect to your service.

Anthony_Roman_6-1609857161187.png

 

Summary

The preceding example use cases are not very complex in nature, yet they provide considerable results to improve the security of your applications. We hope these samples help you understand how flexible Custom Rules can be, and that you can use this as a starting point to build more advanced rule logic in your environment. There are many possibilities to add complexity and effectiveness to these examples, including using Regex to look for patterns in the request body. If you come up with any particularly useful rules, please feel free to share in the comments here or add a sample to our GitHub repository.

 

3 Comments
Occasional Visitor

Hi ,

As per the below linked documentation :

https://docs.microsoft.com/en-us/azure/web-application-firewall/ag/application-gateway-customize-waf...

 

CRS 3.x specific:

  • Inbound anomaly score exceeded threshold

 

What does that mean? I have created a custom rule to whitelist URLs with allow action , but the webpages are still getting blocked with 403 error.

 

New Contributor

In WAF Custom rules what does the RequestUri field contain?

 

Is it the full URI (https://contoso.com/api/controller/1) or only the path (/api/controller/1)?

 

Is there clear documentation on what is available here for the Rule?

Frequent Visitor

Once you have implemented a WAF CustomRule, for example IP Allow, is there a way to update it with/add new IP's to the list and maintain the existing entries using PowerShell?

 

I see where I can create a new policy but it overwrites existing, how can I capture the current IP's and add to the list.

I see that I can go into the portal and add very easily but we are trying to automate this process.

 

Thanks,

Steve

%3CLINGO-SUB%20id%3D%22lingo-sub-2033020%22%20slang%3D%22en-US%22%3EAzure%20WAF%20Custom%20Rule%20Samples%20and%20Use%20Cases%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2033020%22%20slang%3D%22en-US%22%3E%3CP%3EWritten%20in%20collaboration%20with%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F629915%22%20target%3D%22_blank%22%3E%40camilamartins%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20post%20will%20detail%20how%20to%20use%20Custom%20Rules%20on%20Azure%20WAF%2C%20including%20some%20examples%20of%20common%20use%20cases%20fulfilled%20by%20this%20rule%20type.%20Custom%20Rules%20provide%20a%20versatile%20way%20to%20build%20controls%20that%20fulfill%20security%20requirements%20and%20protect%20applications%20from%20attacks%20that%20are%20unique%20to%20your%20applications.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--554731821%22%20id%3D%22toc-hId--554731853%22%3EWAF%20Rule%20Types%20and%20Processing%3C%2FH2%3E%0A%3CP%3EAzure%20WAF%20currently%20offers%203%20rule%20types%2C%20which%20are%20processed%20in%20the%20following%20order%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ECustom%20Rules%20%E2%80%93%20custom%20rules%20are%20processed%20first%2C%20and%20function%20according%20to%20the%20logic%20you%20select.%20This%20makes%20them%20very%20powerful%20as%20the%20first%20line%20of%20defense%20for%20web%20applications.%3C%2FLI%3E%0A%3CLI%3EManaged%20OWASP%20Rules%20%E2%80%93%20OWASP%20rulesets%20are%20based%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSpiderLabs%2Fowasp-modsecurity-crs%2Ftree%2Fv3.1%2Fdev%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESpiderLabs%20Core%20Ruleset%20(CRS)%3C%2FA%3E%2C%20and%20can%20detect%20common%20web%20attacks%20like%20SQL%20injection%2C%20cross-site%20scripting%2C%20and%20command%20injection.%20These%20rules%20cannot%20be%20modified%2C%20but%20the%20ruleset%20can%20be%20tuned%20by%20using%20exclusions%20and%20by%20modifying%20rule%20actions%20(a%20topic%20for%20another%20post).%3C%2FLI%3E%0A%3CLI%3EManaged%20Bot%20Rules%20%E2%80%93%20these%20rules%20identify%20potential%20bot%20activity%20by%20matching%20sources%20against%20our%20internal%20Threat%20Intelligence%20feeds.%20If%20traffic%20is%20coming%20from%20a%20known%20source%20of%20bot%20activity%2C%20the%20traffic%20can%20be%20blocked.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThis%20post%20focuses%20on%20Custom%20Rules%2C%20but%20it%20is%20important%20to%20understand%20how%20the%20managed%20rulesets%20work.%20For%20more%20information%20on%20these%2C%20look%20for%20future%20blog%20posts%20here%20or%20consult%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fweb-application-firewall%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20WAF%20documentation%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1932781012%22%20id%3D%22toc-hId-1932780980%22%3EImportant%20Custom%20Rule%20Concepts%3C%2FH2%3E%0A%3CP%3ECustom%20Rules%20can%20be%20viewed%20and%20built%20using%20the%20Azure%20Portal%20by%20navigating%20to%20Web%20Application%20Firewall%20Policies%20(WAF)%2C%20selecting%20your%20policy%2C%20and%20clicking%20on%20the%20Custom%20Rules%20blade.%20Creating%20a%20custom%20rule%20is%20as%20simple%20as%20clicking%20Add%20Custom%20Rule%20and%20entering%20a%20few%20required%20fields.%20However%2C%20there%20are%20some%20important%20concepts%20to%20understand%20before%20you%20create%20your%20own%20rules.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20most%20important%20thing%20to%20mention%20about%20Custom%20Rules%20is%20that%20they%20are%20terminating.%20This%20means%20that%20if%20the%20logic%20of%20the%20rule%20is%20matched%2C%20all%20other%20rules%20stop%20processing%2C%26nbsp%3Bincluding%20the%20lower%20priority%20(higher%20number)%20Custom%20Rules%2C%20and%20both%20OWASP%20and%20Bot%20managed%20rulesets.%20This%20is%20the%20case%20regardless%20of%20the%20action%20of%20the%20rule%3B%20even%20if%20traffic%20is%20allowed%2C%20no%20further%20rules%20are%20processed.%20This%20can%20have%20positive%20or%20negative%20implications.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Allow%20action%20should%20be%20used%20sparingly%20in%20Custom%20Rules%2C%20because%20since%20the%20rule%20terminates%2C%20it%20means%20that%20all%20other%20inspection%20provided%20by%20WAF%20will%20be%20skipped.%20Understanding%20this%2C%20you%20can%20use%20Allow%20rules%20when%20the%20intent%20is%20to%20skip%20the%20other%20checks%2C%20such%20as%20in%20tuning%20situations.%20If%20certain%20requests%20tend%20to%20trigger%20false%20positives%2C%20you%20can%20use%20a%20Custom%20Rule%20to%20allow%20the%20traffic%20at%20a%20more%20granular%20level%20than%20it%20would%20be%20possible%20by%20using%20exclusions%20or%20disabling%20rules.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20most%20scenarios%2C%20it%20is%20best%20to%20use%20Custom%20Rules%20with%20the%20Deny%20action%2C%20as%20a%20terminating%20Deny%20rule%20is%20entirely%20expected%20and%20without%20unanticipated%20consequences.%20For%20instance%2C%20if%20you%20wanted%20to%20use%20a%20WAF%20Custom%20Rule%20to%20create%20an%20IP%20Address%20allow%20list%2C%20it%20is%20better%20to%20Deny%20traffic%20that%20is%20not%20from%20the%20IP%20addresses%20in%20the%20list%20rather%20than%20Allow%20traffic%20from%20those%20IPs.%26nbsp%3BUsing%20the%20Deny%20action%20avoids%20causing%20traffic%20allowed%20by%20this%20rule%20to%20bypass%20the%20OWASP%20and%20Bot%20rulesets.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20concept%20to%20make%20use%20of%20in%20constructing%20effective%20Custom%20Rules%20is%20compound%20conditions.%20Rules%20can%20be%20created%20with%20a%20single%20condition%2C%20or%20you%20can%20add%20multiple%20conditions%20that%20must%20be%20satisfied%20to%20constitute%20a%20match.%20When%20adding%20multiple%20conditions%2C%20they%20are%20added%20as%20an%20AND%20statement%2C%20so%20all%20conditions%20must%20be%20met%20for%20the%20Action%20to%20take%20place.%20If%20you%20need%20to%20construct%20a%20rule%20with%20OR%20logic%2C%20it%20is%20best%20to%20create%20multiple%20rules%20with%20the%20same%20Action.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-125326549%22%20id%3D%22toc-hId-125326517%22%3ECustom%20Rule%20Example%20Templates%20and%20Use%20Cases%3C%2FH2%3E%0A%3CP%3EWe%20have%20created%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FWAFCustomRuleTemplates%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E2%20ARM%20templates%3C%2FA%3E%2C%20which%20will%20create%20both%20WAF%20Policy%20types%2C%20one%20for%20WAF%20on%20Application%20Gateway%20and%20one%20for%20WAF%20on%20Front%20Door.%20These%20policies%20are%20intended%20to%20give%20you%20a%20starting%20point%20for%20creating%20your%20own%20Custom%20Rules.%20To%20deploy%2C%20simply%20click%20the%20Deploy%20to%20Azure%20buttons%20from%20the%20repository%2C%20select%20a%20Resource%20Group%2C%20and%20create%20your%20policies.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20example%20policies%20must%20be%20modified%20to%20fit%20your%20requirements%20before%20associating%20with%20any%20Front%20Door%20or%20Application%20Gateway%20resources%2C%20and%20the%20following%20sections%20will%20provide%20guidance%20on%20how%20to%20do%20so.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-815888023%22%20id%3D%22toc-hId-815887991%22%3EBlock%20Lists%3C%2FH3%3E%0A%3CP%3ESome%20customers%20have%20the%20requirement%20to%20block%20certain%20sources%20of%20traffic%20based%20on%20IP%20address%20or%20country%20of%20origin.%20In%20these%20scenarios%2C%20block%20lists%20can%20be%20used%2C%20which%20you%20must%20create%20and%20keep%20up%20to%20date.%20The%20examples%20included%20in%20the%20templates%20are%20GeoBlockList%20and%20IPBlockList.%20The%20behavior%20of%20these%20basic%20rules%20can%20be%20modified%20to%20add%20conditions%20if%20necessary.%20For%20example%2C%20you%20may%20want%20to%20block%20a%20certain%20part%20of%20a%20site%20from%20a%20geographic%20region%2C%20as%20pictured%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_1-1609857161165.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244290i21C9059CE59E2030%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_1-1609857161165.png%22%20alt%3D%22Anthony_Roman_1-1609857161165.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotice%20that%20there%20is%20a%20second%20condition%20in%20the%20%22And%20if%22%20box%2C%20which%20defines%20a%20specific%20request%20URI.%20This%20additional%20condition%20creates%20an%20AND%20expression%2C%20meaning%20that%20both%20the%20first%20condition%20about%20geolocation%20and%20the%20second%20condition%20about%20the%20request%20URI%20must%20be%20matched%20in%20order%20for%20the%20Deny%20action%20to%20trigger.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20block%20lists%20can%20be%20added%20manually%20via%20the%20Portal%20or%20managed%20programmatically%20using%20ARM%2C%20API%2C%20or%20CLI.%20One%20example%20of%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-network-security%2Fintegrating-azure-web-application-firewall-with-azure-sentinel%2Fba-p%2F1720306%22%20target%3D%22_blank%22%3Eadding%20to%20a%20block%20list%20automatically%20using%20Azure%20Sentinel%20Playbooks%3C%2FA%3E%20can%20be%20found%20in%20a%20previous%20post.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--991566440%22%20id%3D%22toc-hId--991566472%22%3EAllow%20Lists%3C%2FH3%3E%0A%3CP%3EIP%20address%20or%20geographic%20restrictions%20can%20be%20accomplished%20effectively%20using%20allow%20lists.%20This%20method%20is%20preferable%20if%20you%20only%20do%20business%20in%20certain%20countries%2C%20or%20if%20you%20have%20an%20internal%20website%20you%20would%20like%20to%20be%20available%20only%20to%20trusted%20IP%20addresses%2C%20such%20as%20corporate%20IP%20blocks.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20following%20example%20shows%20the%20IPAllowList%20rule%20found%20in%20the%20template%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_2-1609857161169.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244292i2A84F072EB53FE6B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_2-1609857161169.png%22%20alt%3D%22Anthony_Roman_2-1609857161169.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotice%20that%20the%20allow%20list%20uses%20the%20%22Does%20not%20contain%22%20operator.%20This%20allows%20our%20logic%20to%20use%20the%20Deny%20action%20to%20block%20only%20the%20traffic%20that%20does%20not%20originate%20from%20the%20trusted%20range.%20This%20means%20that%20the%20trusted%20IP%20addresses%20or%20ranges%20will%20continue%20to%20be%20inspected%20by%20the%20other%20applicable%20WAF%20rules.%20Using%20this%20approach%2C%20we%20can%20avoid%20creating%20a%20rule%20using%20the%20%22Does%20contain%22%20operation%20along%20with%20the%20Allow%20action%2C%20which%20would%20result%20in%20a%20rule%20termination%20scenario%20that%20would%20exempt%20the%20trusted%20traffic%20from%20further%20WAF%20inspection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1495946393%22%20id%3D%22toc-hId-1495946361%22%3EControlling%20Allowed%20HTTP%20Methods%3C%2FH3%3E%0A%3CP%3EHTTP%20method%20enforcement%20can%20be%20done%20in%20a%20dynamic%20way%20using%20WAF%20Custom%20Rules.%20Consider%20the%20scenario%20where%20you%20have%20an%20API%20that%20should%20be%20available%20publicly%20for%20customers%20to%20GET%20and%20POST%2C%20but%20you%20want%20to%20reserve%20PUT%20and%20DELETE%20actions%20for%20traffic%20originating%20from%20trusted%20locations%20as%20an%20extra%20layer%20of%20security%20beyond%20authentication.%20The%20following%20modification%20of%20the%20MethodAllowList%20rule%20can%20be%20used%20to%20accomplish%20this.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_3-1609857161178.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244291iE66A797EC04943E8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_3-1609857161178.png%22%20alt%3D%22Anthony_Roman_3-1609857161178.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--311508070%22%20id%3D%22toc-hId--311508102%22%3EBlocking%20User%20Agents%3C%2FH3%3E%0A%3CP%3ESome%20of%20the%20OWASP%20managed%20rules%20will%20detect%20well%20known%20malicious%20user%20agents%2C%20but%20if%20you%20find%20the%20need%20to%20block%20a%20specific%20set%2C%20a%20Custom%20Rule%20is%20a%20way%20to%20accomplish%20this.%20Of%20course%2C%20user%20agent%20is%20not%20a%20difficult%20element%20for%20an%20attacker%20to%20change%2C%20but%20this%20type%20of%20rule%20can%20help%20deflect%20unsophisticated%20attackers.%20The%20logic%20of%20the%20UserAgentBlock%20rule%20is%20represented%20in%20the%20template%20pictured%20below.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_4-1609857161181.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244293i3D88C4164179CCA7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_4-1609857161181.png%22%20alt%3D%22Anthony_Roman_4-1609857161181.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--2118962533%22%20id%3D%22toc-hId--2118962565%22%3ERate%20Limiting%20with%20WAF%20for%20Front%20Door%3C%2FH3%3E%0A%3CP%3EWAF%20on%20Azure%20Front%20Door%20has%20the%20added%20capability%20of%20Custom%20Rules%20with%20a%20Rate%20Limit%20type%2C%20as%20distinct%20from%20Match%20type%20rules.%20Rate%20Limit%20rules%20will%20keep%20track%20of%20the%20number%20of%20requests%20from%20a%20particular%20IP%20address%20and%20block%20requests%20made%20after%20a%20threshold%20is%20reached.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20rules%20can%20be%20part%20of%20an%20effective%20layer%207%20DDoS%20protection%20strategy.%20Azure%20DDoS%20Protection%2C%20both%20at%20the%20platform%20level%20(free)%20and%20using%20the%20Standard%20tier%20(paid)%20will%20protect%20against%20high%20volume%20attacks%2C%20but%20there%20are%20application%20attacks%20that%20do%20not%20necessarily%20rely%20on%20high%20volume.%20Some%20of%20these%20attacks%20can%20be%20mitigated%20by%20using%20source%20rate%20limiting%20in%20Custom%20Rules.%20The%20idea%20is%20that%20a%20legitimate%20user%20of%20a%20site%20will%20make%20a%20predictable%20number%20of%20requests%20to%20the%20site%20over%20a%20given%20time%20period%2C%20but%20an%20attacker%20trying%20to%20disrupt%20the%20site%E2%80%99s%20availability%20would%20likely%20make%20more%20requests.%20A%20threshold%20can%20be%20set%20to%20limit%20the%20volume%20of%20traffic%20to%20a%20particular%20path%20from%20a%20source%2C%20as%20pictured%20below.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_5-1609857161185.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244295iB9B0B137E4FDACDC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_5-1609857161185.png%22%20alt%3D%22Anthony_Roman_5-1609857161185.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20above%20rate%20limiting%20rule%2C%20100%20requests%20from%20the%20same%20IP%20address%20would%20be%20allowed%20within%20any%201%20minute%20time%20period%2C%20but%20after%20the%20threshold%20is%20met%2C%20additional%20requests%20from%20that%20IP%20would%20be%20dropped%20for%201%20minute.%20After%20the%20rate%20limiting%20period%20expires%2C%20traffic%20is%20allowed%20and%20the%20counter%20to%20100%20starts%20again.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-368550300%22%20id%3D%22toc-hId-368550268%22%3EUsing%20WAF%20on%20Application%20Gateway%20to%20only%20Allow%20Traffic%20from%20your%20Front%20Door%3C%2FH3%3E%0A%3CP%3EA%20common%20architectural%20design%20is%20to%20use%20Azure%20Front%20Door%20to%20provide%20global%20load%20balancing%20and%20content%20distribution%20in%20front%20of%20Application%20Gateways%20hosted%20in%202%20or%20more%20regions.%20NSGs%20can%20be%20used%20on%20the%20Application%20Gateway%20subnet%20to%20only%20allow%20traffic%20from%20the%20Front%20Door%20service%2C%20but%20the%20remaining%20security%20concern%20here%20is%20that%20Front%20Door%20is%20a%20shared%20service.%20You%20probably%20want%20to%20allow%20traffic%20only%20from%20your%20Front%20Door%20service%20specifically%20to%20prevent%20an%20attacker%20from%20setting%20up%20a%20%E2%80%9Crogue%E2%80%9D%20Front%20Door%20instance%20without%20WAF%20in%20order%20to%20circumvent%20inspection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFortunately%2C%20Front%20Door%20adds%20a%20header%20(X-Azure-FDID)%20to%20all%20traffic%20it%20processes%2C%20which%20identifies%20it%20as%20your%20instance%20of%20Front%20Door.%26nbsp%3BPictured%20below%20is%20a%20WAF%20Custom%20Rule%2C%20AllowFrontDoor%20in%20the%20template%2C%20that%20will%20only%20allow%20traffic%20that%20contains%20this%20specific%20header%20value.%20This%20guarantees%20that%20traffic%20sourcing%20from%20unapproved%20Front%20Door%20instances%20will%20not%20connect%20to%20your%20service.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_6-1609857161187.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244294i71E36D89C852F09E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_6-1609857161187.png%22%20alt%3D%22Anthony_Roman_6-1609857161187.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-358047196%22%20id%3D%22toc-hId-358047164%22%3ESummary%3C%2FH2%3E%0A%3CP%3EThe%20preceding%20example%20use%20cases%20are%20not%20very%20complex%20in%20nature%2C%20yet%20they%20provide%20considerable%20results%20to%20improve%20the%20security%20of%20your%20applications.%20We%20hope%20these%20samples%20help%20you%20understand%20how%20flexible%20Custom%20Rules%20can%20be%2C%20and%20that%20you%20can%20use%20this%20as%20a%20starting%20point%20to%20build%20more%20advanced%20rule%20logic%20in%20your%20environment.%20There%20are%20many%20possibilities%20to%20add%20complexity%20and%20effectiveness%20to%20these%20examples%2C%20including%20using%20Regex%20to%20look%20for%20patterns%20in%20the%20request%20body.%20If%20you%20come%20up%20with%20any%20particularly%20useful%20rules%2C%20please%20feel%20free%20to%20share%20in%20the%20comments%20here%20or%20add%20a%20sample%20to%20our%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FAzNetSec%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%20repository%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2033020%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20use%20Azure%20WAF%20Custom%20Rules%20to%20address%20common%20application%20and%20network%20security%20scenarios.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Anthony_Roman_0-1609857110032.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F244289i71CB5C97427D4195%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Anthony_Roman_0-1609857110032.png%22%20alt%3D%22Anthony_Roman_0-1609857110032.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2033020%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Application%20Gateway%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20DDoS%20Protection%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Front%20Door%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20WAF%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2021 06:15 AM
Updated by: