DDoS Protection
Arvancloud's Distributed Denial of Service (DDoS) Protection helps you protect your website against DDoS attacks in four modes with different levels of complexity.
To use DDoS Protection, simply go to CDN > DDoS Protection in the Arvancloud panel.
Layer 3 and 4 DDoS Protection
In the basic mode, the first level of Arvancloud DDoS protection, all attacks at network layers 3 and 4 are repelled, and your website is protected against them. However, this mode doesn't prevent layer 7 attacks, which are more complex.
To prevent this type of attack, Arvancloud offers three modes: General, Professional, and Advanced.
Layer 7 DDoS Protection
This protection works at the application layer, at three levels.
Cookie Challenge
When you enable the Cookie challenge, Arvancloud sends a response with status code 307 to each user's first request and asks the user to apply a specific cookie from the response and send it with all subsequent requests. Arvancloud then checks this cookie and, if it is valid, allows access to the site. (If this redirect disrupts your APIs, you can create a rule for that API in the Custom Rules section to disable this feature for it.) With this challenge, most simple bots can be identified and blocked.
The IPs of Google and other search engines are exempt from all DDoS protection measures.
Enabling via API
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/ddos' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: fa' \
--header 'authorization: APIKEY 1 2 3 4' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json;charset=UTF-8' \
--header 'pragma: no-cache' \
--data-raw '{"protection_mode":"cookie"}'
JS Challenge
When you enable the JS challenge, a type of cryptographic operation is used to identify normal users and prevent attacks by advanced bots as well. In this method, a JavaScript file is sent to the user's browser, which is asked to complete an AES encryption challenge. Since this challenge requires CPU usage and a JavaScript engine, robots can't pass it.
Enabling via API
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/ddos' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: fa' \
--header 'authorization: APIKEY 1 2 3 4' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json;charset=UTF-8' \
--header 'pragma: no-cache' \
--data-raw '{"protection_mode":" javascript"}'
Captcha Challenge
In the last and most advanced challenge, the user is shown a security code (Captcha) and asked to correctly identify several images. Because the traffic for showing these pages and processing them is handled outside your server, no load is added on your server.
In this mode, you can specify the captcha type according to your needs, which determines the captcha used across the whole domain in DDoS challenge mode 3 (the Captcha challenge).
To enable the Captcha challenge, your CDN plan must be Professional or Enterprise.
Enabling via API
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/ddos' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: fa' \
--header 'authorization: APIKEY 1 2 3 4' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json;charset=UTF-8' \
--header 'pragma: no-cache' \
--data-raw '{"protection_mode":"recaptcha"}
Changing the Captcha Type via API
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/ddos' \
--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 '{"protection_mode":"captcha","captcha_service":"hcaptcha","ttl":0}'
The captcha_service parameter accepts three values: hCaptcha, arCaptcha, and reCAPTCHA, which you send in the API request depending on the service you choose.
In each of the DDoS protection challenges, you can set the challenge's validity period per user, meaning how long a verified user doesn't need to be verified again.
Disabling DDoS Protection for a Specific Path
If the DDoS challenge disrupts a path of your domain (such as an API service), you need to enter that path (URL) in Arvancloud in Glob format so the DDoS challenge isn't applied to it.
To do this, click Add Rule in the Custom Rules section.
You can now enter the path along with a list of IPs, or all IPs, and specify whether the challenge is applied to them or not.
Notes on Using fetch or xhr While a Challenge Is Active
If your domain (example.com) has JavaScript code that sends requests to a subdomain (such as sub.example.com), note the following:
Using fetch
If you use fetch to send requests, set credentials to include in options. Example:
fetch("https://sub.example.com", { credentials: 'include' });
Using xhr
If you use xhr, set the client's withCredentials to true. Example:
let xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://sub.example.com", true);
xhttp.withCredentials = true;
xhttp.send();
Using ajax
If you use ajax, set the xhrFields.withCredentials option to true. Example:
$.ajax("https://sub.example.com", { xhrFields: { withCredentials: true } })
Handling Preflight or CORS Requests
To send requests to a subdomain, the Preflight headers must be handled in some way (for example, with page rules).
If you don't need the response to the sent request (the request is opaque), you can set mode to no-cors. Example:
fetch("https://sub.example.com", { mode: 'no-cors', credentials: 'include' })