Web Application Firewall | WAF
The Arvancloud Web Application Firewall (WAF) blocks malicious requests using regex rules and the Anomaly Scoring method. Anomaly Scoring is a highly accurate way to detect attacks. In this method, each rule is assigned a score. When several rules match a request, the scores of the matched rules are added up and compared with the threshold set for the WAF (the sensitivity level). If the score of the rules matched with that request is equal to or greater than the sensitivity level set for the WAF, the request is blocked.
This guide explains how to configure the Arvancloud WAF.
Configuring the WAF in the Arvancloud Panel
To configure the WAF in the Arvancloud panel, go to CDN and then Web Application Firewall (WAF).
In the general WAF settings, you can set your WAF to one of the three modes in the Web Application Firewall section.
-
Selecting Off disables the WAF for your website.
Turning off the WAF via API:
curl --location --request PATCH https://napi.arvancloud.ir/cdn/4.0/domains/example.com/waf'' \--header 'authority: napi.arvancloud.ir' \--header 'accept: application/json, text/plain, */*' \--header 'authorization: API KEY 1 2 3 4' \--header 'cache-control: no-cache' \--header 'content-type: application/json' \--data-raw '{"mode":"off"}' -
If the WAF is set to Detection on this page, it only records logs. Note that in this mode, no incoming request is blocked.
Enabling Detection mode via API:
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/waf' \--header 'authority: napi.arvancloud.ir' \--header 'accept: application/json, text/plain, */*' \--header 'authorization: API KEY 1 2 3 4' \--header 'cache-control: no-cache' \--header 'content-type: application/json' \--data-raw '{"mode":"detect"}' -
Selecting On enables the WAF for your website and blocks suspicious requests.
Turning on the WAF via API:
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/waf' \--header 'authority: napi.arvancloud.ir' \--header 'accept: application/json, text/plain, */*' \--header 'authorization: API KEY 1 2 3 4' \--header 'cache-control: no-cache' \--header 'content-type: application/json' \--data-raw '{"mode":"protect"}'
We recommend that when you first set up the WAF, you put it in Detection mode for a short period. This way, real attacks can be identified.
After this period, go to Security > WAF Attack Analysis, then Attack Details. In this section, click any attack to see its details and the related error code.
Based on these reports, you can identify false positives. False positives are legitimate requests that the WAF mistakenly identifies as attacks. Once false positives are identified, you can determine which rules should be disabled. Take the ID from the report output, search for it in the related security package to find the rule, and disable it.
Turning off a specific rule via API:
To do this, send the disabled_rules parameter with the numbers of the rules you want.
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/waf/packages/default?revelio' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data-raw '{"disabled_rules":["21001","21003","21006","21009","40026","99001","21002"]}'
After the period set for keeping the WAF in Detection mode ends, go to the WAF settings, select On, and adjust the rules and set the sensitivity level according to what you learned from the reports.
Note that while the WAF is enabled, the maximum request body size is 524288 bytes.
The higher the sensitivity number, the more rules must match the incoming request, which means lower WAF sensitivity. In other words, the relationship between the number set for sensitivity and the strength of the WAF is inverse. So a lower number means higher WAF sensitivity.
Packages
With security packages, you can add preconfigured settings to the WAF according to your needs. Each security package contains different settings; when you enable a package, these settings are applied to your WAF and used to inspect requests.
Currently, besides the default Arvancloud WAF package, two standard packages, CRS and Comodo, can also be enabled and used from the Packages section of the WAF panel.
Arvancloud WAF Package
This package is Arvancloud's default rule set for use with the WAF. The features and rules of this package are described below.
-
Malicious XSS code execution (code 42xxx)
This attack results from the browser executing given input (malicious code) without proper validation. In this attack, the attacker uses various methods, such as sending a URL by email or uploading to vulnerable parts of a website, to run their malicious script in another user's browser and take control of the victim's browser.
-
SQL Injection attacks (code 41xxx)
In this attack, the attacker sends an unwanted SQL query from the user side to the server through form input data or URL parameters. This attack can create, edit, delete, and read confidential information, change database data, or create unauthorized access for a specific user (such as the attacker gaining admin access).
-
Anomalous requests (code 21xxx)
In this category, the attacker targets the HTTP protocol, and the WAF checks HTTP headers to validate things such as whether the header is valid and contains a valid value, and on this basis distinguishes correct HTTP headers from incorrect ones.
-
Malicious bots (code 35xxx)
In this section, the WAF prevents the activity of malicious bots. Normal bots all follow the WAF rules and are not blocked by it. Only bots that try to violate the WAF rules and look for various vulnerabilities in applications are blocked by the WAF.
-
Blocking non-standard HTTP requests (code 20xxx)
In this mode, the WAF checks that the HTTP protocol is used correctly; for example, whether POST/GET methods have a body or whether a POST request includes a Content-Length header.
-
General attacks (code 40xxx)
In this category of attacks, the attacker exploits the lack of input/output data validation and injects malicious code into the application. When the application interprets this code, the attacker can perform actions such as stealing information or bypassing authentication. The best-known of these attacks are Remote File Inclusion (RFI) and Local File Inclusion (LFI).
Sensitivity Level
The sensitivity level can be set at 8 levels:
- 0 (Emergency)
- 1 (Alert)
- 2 (Critical)
- 3 (Error)
- 4 (Warning)
- 5 (Notice)
- 6 (Info)
- 7 (Debug)
Score Calculation Based on Sensitivity Level
In this system, the sensitivity level (severity) determines which categories of rules take part in calculating the score. In other words, the severity type specifies which counters are considered when calculating the final score.
Suppose we have four different severity levels, each with its own counter:
- severity_1
- severity_2
- severity_3
- severity_4
For each rule assigned to one of these levels, when it matches, the value of that specific severity increases. For example, if a rule belongs to severity_1, when this rule matches, the value of severity_1 increases. Likewise, if the rule is in severity_2, when it matches, the value of severity_2 increases, and the same goes for the other levels.
These values must be added up to calculate the request's final score. However, which values are added up is determined by the severity. For example:
- When severity=1: total_score = severity_1
- When severity=3: total_score = severity_1 + severity_2 + severity_3
Finally, this total_score is compared with the threshold, and if it is greater than the threshold, the request is blocked.
Setting the Sensitivity Level and Its Effect on the WAF
Based on the above, if the sensitivity level is set to 0 (Emergency), the WAF is at its least strict, and only rules with Emergency sensitivity are checked. In other words, in this mode only rules belonging to the Emergency sensitivity are checked, and the final score is calculated based on them.
Conversely, if the sensitivity level is set to 6 (Info), the WAF is at its strictest, and all rules, from the most lenient to the strictest, are checked. In this mode, all rules from the different severity levels (from Info to Emergency) take part in calculating the final score.
So, by changing the sensitivity level, you can set how strict the WAF is, so that only rules with a specific sensitivity or all rules are checked.
CRS Package
This package contains general rules for detecting attacks and can be used with the Arvancloud WAF. By enabling the WAF and selecting the CRS package in the panel, you can protect your website against various attacks. Protection against the following common attacks is part of the CRS package:
- SQL Injection (SQLi)
- Cross Site Scripting (XSS)
- Local File Inclusion (LFI)
- Remote File Inclusion (RFI)
- PHP Code Injection
- Java Code Injection
- HTTPoxy
- Shellshock
- Unix/Windows Shell Injection
- Session Fixation
- Scripting/Scanner/Bot Detection
- Metadata/Error Leakages
Comodo Package
This package can also be selected and applied alongside the other packages from the related section of the Arvancloud panel. The Comodo package rules include the main Intrusion Protection and Advanced Filtering rulesets.
Custom Rules
In the Arvancloud WAF, you can enable or disable WAF protection for a specific path of the domain or for an IP range.
To do this, first go to Web Application Firewall (WAF) in the CDN panel, and then click Add Rule in the Custom Rules section.
In this step, enter the requested path in Glob format and the IP or IP range you want the rule to apply to. Finally, select the action.
After the rule is created, the created items are shown in a list along with their priority, and you can edit the rules on the same page.
Priority determines which rules run first, and if there are several rules for a specific path, which rule runs first. Note that the lower a rule's priority value, the sooner it runs. For example, a rule with priority 1 runs before a rule with priority 10.
Creating a Custom Rule via API
To set the rule's action, send the action parameter with protect for protection or passthrough for no protection.
curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/waf/rules' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY 1 2 3 4' \
--header 'content-type: application/json' \
--data-raw '{"id":null,"url_pattern":"example.com/**","sources":["192.168.1.1/32"],"description":"Test For Docs","action":"protect"}'
Excluding Specific Rules
In custom rules, you can exclude one or more specific rules for a path pattern. In this case, the selected rule(s) are not checked for that path.
WAF Attack Analysis
In the Arvancloud WAF reports section, you can view and analyze the types of detected attacks.
In the Attack Details section, you can see the attack logs and, if needed, turn the related rules on or off based on your site's normal behavior.
For each attack, you can click its log to see more details.
You can see, in order:
- The attacker's IP
- The request method
- The attacked address
- The time
- The sent cookies
- The User Agent
At the end, you can see the rules the request matched, note their IDs if needed, and turn them off in the WAF section.
In the Attacks by Map section, you can also see the regions your site was attacked from.