Skip to main content

Firewall Settings

The new generation of the Arvancloud firewall provides a flexible platform for controlling the HTTP requests of your website or web application. The Arvancloud CDN firewall settings help you combine several conditions to create rules that control your domain's traffic and secure your website and web application.

The Arvancloud firewall lets you inspect and block suspicious incoming traffic to your site by defining rules based on Wireshark syntax. You can do this through the panel or the CDN API. This guide explains how to enable the firewall and define different rules in the Arvancloud CDN firewall.

Enabling and Configuring the Firewall in the Panel​

To manage and configure firewall rules, go to Firewall Settings in the CDN Security menu of the panel. Using the options in the Default Rule section, you can make your website generally accessible by selecting Allow, or take it offline by selecting Block. The default rule applies when the requester's conditions don't match any of the defined rules.

To define firewall rules, simply click Add Rule. On the Create New Rule page, you can set the rule's name and description, the condition's parameter, operator, and value, and also review the rule's equivalent expression. Finally, after completing the conditions, you can choose the action to allow or block access.

To create a condition, first select the HTTP property you want in the Parameter field from the following variables.

ParameterDescription
IP Source AddressThe requester's IP

Sample value: 1.2.3.4
CountryThe requester's country of origin

Sample value: IR
AS NumThe requester's Autonomous System Number (ASN)

Sample value: 44244
CookieThe full cookie value as a string

Sample value: SSID=AjMisfbW7_GcDfpgd;session=8521F670545D7865F79C3D7BEDC29CCE
HostnameThe host name used in the request

Sample value: www.example.com
ReferrerThe request's HTTP Referer header, which contains the address of the page that linked to the currently requested page.

Sample value: developer.example.com/docs/Web/JavaScript
User AgentThe request's user agent, which contains a string identifying the user's operating system and browser.

Sample value: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Request MethodThe HTTP request method as an uppercase string

Sample value: GET
URIThe URI path and query string

Sample value: /help/index?section=539061&expand=comments
URI PathThe request's URI path

Sample value: /help/index
URI Query StringThe full query string without ?

Sample value: section=539061&expand=comments
URI ArgsSample value: key=value
HTTP VersionThe HTTP protocol version used in the request

Sample value: HTTP/1.1
X-Forwarded-ForThe value of the x-forwarded-for header

This parameter can only be used in regex

Sample values:

any(http.x_forwarded_for[] in {1.1.1.0 1.2.3.4})

any(http.x_forwarded_for[] == 1.1.1.0)

any(http.x_forwarded_for[*] != 1.1.1.0)
Request HeadersThe request's (custom) headers

Sample value:

http.request.headers["x-custom-header"] == "special-value"
SSL/HTTPSWhether SSL/HTTPS is used in requests

Sample value: True or False
Known BotWhether the request is from a Known Bot

Sample value: True or False
JA3 FingerprintThe JA3 Fingerprint value

To use this parameter, you need to enable JA3 Fingerprint calculation in the Connection to Edge Servers settings.

Sample value:

771,4865-4866-4867,0-11-10-35-56-57-61-62-130-131,23-24,0

Currently, these parameters are fully available on the Enterprise plan, and the IP Source Address, Country, Hostname, and URI parameters are available on all plans.

Next, select the operator you need from the following table and set a value for the condition.

OperatorDescription
EqualsEquivalent to == and specifies that the parameter and the value must be equal
Does not equalEquivalent to != and specifies that the parameter and the value must not be equal
ContainsEquivalent to contains and specifies that the parameter must contain a value
Matches REGEXEquivalent to ~ and specifies that the parameter must match the regex value
Is in listEquivalent to in and specifies that the parameter's values must be in the list
Starts withSpecifies that the parameter must start with the specified value
Ends withSpecifies that the parameter must end with the specified value

You can define several conditions in one rule to allow or block the requests you want. If you combine several conditions with and, all conditions must be met; if you use or, only one of the conditions needs to be met for the rule to apply.

For example, suppose you want to define a rule that blocks all incoming POST requests to a specific path, such as example.com/test, from a specific source IP and a specific user agent, such as Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36. To do this, add four conditions combined with and: IP Source Address equals 1.2.3.4, URI Path equals /test, Request Method equals POST, and User Agent equals the user agent above, then set the action to Block.

In the Equivalent Expression section, you can review the expression equivalent to the defined conditions and rule. A simple expression compares a value from the HTTP request with the value defined in the expression and is built in the form <parameter> <operator> <value>, such as ip.src==1.2.3.4. Compound expressions are simple expressions combined with the and/or operators into a single expression. They are built in the form <simple expression> <logical operator> <simple expression>, such as ((ip.src==1.2.3.4) and (http.request.method=='POST')). Each firewall rule has an equivalent expression based on its defined conditions.

After defining and creating rules, you can edit, prioritize, and delete them in the Rules List section.

Also, if the Professional or Enterprise plan is active on your domain, you can see the list of visitor IPs and their number of requests in Firewall Settings.

Checking URL-Encoded Characters in Firewall Rules​

In HTTP requests, special characters may be sent URL-encoded. For example, the following path:

/helloπŸ‘‹πŸ»

may be sent like this:

/hello%F0%9F%91%8B%F0%9F%8F%BB

To check this value in firewall rules, two parameters are available: http.request.uri shows the raw, URL-encoded value of the request, and http.request.uri.path shows the decoded value of the path. For the example above:

http.request.uri = /hello%F0%9F%91%8B%F0%9F%8F%BB
http.request.uri.path = /helloπŸ‘‹πŸ»

Note that if you want to write a rule that is not sensitive to URL encoding, it is better to define it based on the processed path. For example:

http.request.uri.path contains "hello"

or:

http.request.uri.path contains "media"

This way, requests whose characters are sent URL-encoded are also detected.

Rule Name, Description, and Status​

Each rule in the Arvancloud CDN firewall has a name, a description, and a status.

For example, you can give your rule a name and enter a description of what it does, to make it easier to identify and work with rules. Finally, with the status field, you can enable or disable the rule.

The name, description, and status of rules can be defined in the API with the name, note, and is_enabled parameters; is_enabled accepts true and false.

Setting the Firewall's Behavior When a Condition Is Met​

In the Arvancloud CDN firewall, you can specify how the firewall behaves when the conditions in a rule are met. The actions you can choose are Allow, Block, Challenge, and Bypass security mechanisms.

Allow​

In this mode, Arvancloud responds to requests that match the defined conditions.

Creating a rule with the Allow action via API:

curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--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 '{"name":"Test Rule","note":"","is_enabled":true,"action":"allow","action_details":{"mode":1,"ttl":120,"https_only":false},"filter_expr":"((http.host == \"example.com\"))"}'

Block​

In this mode, Arvancloud doesn't allow the request to be processed and returns a 403 error.

Creating a rule with the Block action via API:

curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--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' \

--header 'origin: https://panel.arvancloud.ir' \

--header 'pragma: no-cache' \

--data-raw '{"name":"deny rule","note":"","is_enabled":true,"action":"deny","action_details":{"mode":1,"ttl":120,"https_only":false},"filter_expr":"((http.host == \"example.com\"))"}'

Challenge​

In this mode, if one of the conditions is met, the user faces a DDoS challenge. You can also specify the type of DDoS challenge and how long it stays valid.

Creating a rule with the Challenge action via API:

curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--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' \

--header 'origin: https://panel.arvancloud.ir' \

--header 'pragma: no-cache' \

--data-raw '{"name":"challenge","note":"challenge","is_enabled":true,"action":"challenge","action_details":{"mode":1,"ttl":120,"https_only":false},"filter_expr":"((http.host == \"example.com\"))"}'
  • When creating a rule with the Challenge action via API, the mode parameter can be 1, 2, or 3: 1 is the Cookie challenge, 2 the JS challenge, and 3 the Captcha challenge.
  • The ttl parameter is how long the DDoS challenge is valid; until it expires, the user is not verified again.

Bypass Security Mechanisms​

In this mode, you can specify which security mechanisms should not run when the firewall conditions are met. These mechanisms include Rate Limit, Web Application Firewall (WAF), and DDoS protection.

Creating a rule with the Bypass action via API:

curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--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' \

--header 'origin: https://panel.arvancloud.ir' \

--header 'pragma: no-cache' \

--data-raw '{"name":"ByPass","note":"","is_enabled":true,"action":"bypass","action_details":{"waf":true,"rlimit":true,"challenge":true},"filter_expr":"((http.host == \"example.com\"))"}'

Enabling and Configuring the Firewall via API​

Besides the panel, all settings and features of the Arvancloud CDN firewall can also be defined via API. With the APIs in the following table, you can change and review the firewall settings.

APIDescription
GET DOMAIN'S FIREWALL CONFIGURATIONGet the default firewall settings
UPDATE DOMAIN'S FIREWALL CONFIGURATIONEdit the default firewall settings
CREATE NEW FIREWALL RULECreate a new firewall rule
GET FIREWALL RULE INFORMATIONGet information about a firewall rule
UPDATE THE FIREWALL RULEEdit a firewall rule
DELETE FIREWALL RULEDelete a firewall rule
CHANGE PRIORITY OF FIREWALL RULESChange the priority of a firewall rule

For example, the example from the previous section looks like this via API:


curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--header 'Authorization: Apikey XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX' \

--header 'Content-Type: application/json' \

--data-raw '{

"name": "test",

"note": "test rule",

"is_enabled": true,

"action": "deny",

"filter_expr": "(((ip.src == 1.2.3.4) and (http.request.uri.path == \"/test\") and (http.request.method == \"POST\") and (http.user_agent == \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36\")))"

}'

To write the value of the filter_expr parameter, write an expression based on Wireshark rules. You can also use the following table to specify the expression's values.

ParameterEquivalent
SOURCE IP ADDRESSip.src
COUNTRYip.geoip.country
URI PATHhttp.request.uri.path
HOSTNAMEhttp.host
COOKIEhttp.cookie
REFERERhttp.referer
REQUEST METHODhttp.request.method
URIhttp.request.uri
URI QUERY STRINGhttp.request.uri.query
HTTP VERSIONhttp.request.version
USER AGENThttp.user_agent
REQUEST HEADERS RAWhttp.request.headers.raw

To review the API documentation for this feature, see this section. To get an access key (API key), see the article "Getting an Access Key".

Common Use Cases​

This section covers some common use cases of this generation of the Arvancloud CDN firewall and how to set them up.

  • Requiring a specific cookie:

    To secure a specific environment, such as a development environment, you can share a cookie with trusted people and then filter requests so only users with that cookie can access the specific path you want. To do this, use the Cookie parameter and define two rules. Suppose you want to allow only three of your colleagues to access dev.example.com. First, define a rule to block access to dev.example.com, and then a rule like the following to allow access for those people.

    Note that the allow rule must have a higher priority.


curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--header 'Authorization: Apikey XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX' \

--header 'Content-Type: application/json' \

--data-raw '{

"name": "acess",

"note": "dev access",

"is_enabled": true,

"action": "allow",

"filter_expr": "((http.cookie == \"acess=x\") or (http.cookie == \"acess=y\") or (http.cookie == \"acess=z\"))"

}'
  • Mitigating R.U.D.Y attacks:

    R.U.D.Y attacks are a type of DoS attack that take down a web server by sending requests with very large headers to waiting sessions. The way to mitigate these attacks is to block requests that don't contain a verified session cookie. This example combines three conditions to counter POST requests that don't have a valid cookie.

    The first condition uses the URI path parameter to specify the paths that need protection against R.U.D.Y:

    ((http.request.uri.path == "(comment|conversation|event|poll)/create"))

    The second condition specifies the format of a verified, valid cookie:

    ((http.cookie matches "auth_session=[0-9a-zA-Z]{32}-[0-9]{10}-[0-9a-z]{6}"))

    And the third condition specifies requests with methods other than POST:

    ((http.request.method != "POST"))

    The three conditions are combined with the and operator, and the rule's action is Allow.


curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--header 'Authorization: Apikey XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX' \

--header 'Content-Type: application/json' \

--data-raw '{

"name": "RUDY",

"note": "",

"is_enabled": true,

"action": "allow",

"filter_expr": "(((http.request.method != \"POST\") and (http.cookie matches \"auth_session=[0-9a-zA-Z]{32}-[0-9]{10}-[0-9a-z]{6}\") and (http.request.uri.path == \"\"(comment|conversation|event|poll)/create\")))"

}'

  • Preventing hotlinking:

    Hotlinking is known as stealing a site's bandwidth by linking directly to its elements, such as images or videos. With the new generation of the Arvancloud firewall and appropriate rules, you can prevent hotlinking. To do this, use the referer and URI path parameters to protect the path you want against hotlinking. In this rule, all requests sent to the path from a referer other than our site (here, example.com) are blocked, and only requests sent from our website are allowed.


curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/firewall/rules' \

--header 'Authorization: Apikey XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX' \

--header 'Content-Type: application/json' \

--data-raw '{

"name": "Hotlink Protection",

"note": "block other referee",

"is_enabled": true,

"action": "deny",

"filter_expr": "(((http.referer != \"example.com\") and (http.request.uri != \"/hotlink-ok/\")))"

}'