To protect your business from malicious IP scraping or attacks, configure an IP blacklist/whitelist to filter requests by source IP address at CDN points of presence (POPs). A blacklist blocks known malicious IP addresses, while a whitelist allows only trusted traffic. This protects your origin server from attacks.
Use cases
Configuration | Use case |
IP whitelist |
|
IP blacklist |
|
Billing
The IP Blacklist or Whitelist feature is free of charge. However, blocked requests still incur minor fees. Since the block occurs after the request is processed by the CDN POP (Layer 7), the associated traffic and requests are still billable:
Data transfer: A blocked request generates traffic for one request (including the HTTP header) and one response (a 403 page). This traffic is billed as standard CDN data transfer.
HTTPS requests: If the domain uses the HTTPS protocol, the TLS handshake is completed before the IP is blocked. Therefore, each blocked HTTPS request is still counted and billed as one HTTPS request.
Before you begin
A domain name can have only one IP blacklist or one IP whitelist rule. The two are mutually exclusive.
After you configure an IP blacklist, requests from blocked IPs are rejected with a 403 status code at the CDN POPs, but they are still recorded in your CDN logs. This is expected behavior and confirms that the blacklist is working correctly.
A few Internet Service Providers (ISPs) may assign private IP addresses to end users in certain regions. As a result, POPs receive the user's private IP address.
NotePrivate IP addresses are:
Class A: 10.0.0.0 to 10.255.255.255. Subnet mask: 10.0.0.0/8.
Class B: 172.16.0.0 to 172.31.255.255. Subnet mask: 172.16.0.0/12.
Class C: 192.168.0.0 to 192.168.255.255. Subnet mask: 192.168.0.0/16.
Procedure
Log on to the Alibaba Cloud CDN console.
On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
In the left navigation tree of the domain name, click Access Control.
In the IP Blacklist or Whitelist section, click Modify.
Use the examples below for a quick setup. You can also refer to the Parameter description to add a configuration.
Example 1: Protect the management console (Whitelist + Rules Engine)
Goal: Allow only the office egress IP addresses
203.x.x.10and203.x.x.11to access the/admin/path.Configuration:
Type: Select Whitelist.
Rules: Enter
203.x.x.10and203.x.x.11(separate by a line feed).Advanced Configuration - IP Rules: Select Determine based on the IP address that is used to connect to the POP.
Advanced Configuration - Rule Condition: On the Rules Engine page, configure a rule where the URI contains
/admin/*(case-insensitive). Then, select this rule in the Rule Condition section.
Result: Only requests from these two IP addresses can access the
/admin/directory. All other requests to this directory will be rejected with a 403 status code.
Example 2: Allow access from a partner's IPv6 CIDR block (Whitelist)
Goal: Allow access only from the partner's IPv6 CIDR block
FC00:0AA3:0000:0000:0000:0000:0000:0000/48.Configuration:
Type: Select Whitelist.
Rules: Enter
FC00:0AA3:0000:0000:0000:0000:0000:0000/48.Advanced Configuration - IP Rules: Select Determine based on the IP address that is used to connect to the POP.
Result: Only requests from this IPv6 CIDR block can access your domain name resources.
Example 3: Block an attack source (Blacklist)
Goal: A CC attack is detected from the
198.x.x.0/24network segment and must be blocked immediately.Configuration:
Type: Select Blacklist.
Rules: Enter
198.x.x.0/24.Advanced Configuration - IP Rules: Select Determine based on the IP address that is used to connect to the POP.
Result: All IP requests from the
198.x.x.0/24CIDR block are rejected by CDN POPs.
Parameter description
Parameter | Description |
Type | Select Blacklist or Whitelist.
|
Rules | Rule format requirements
Rule length limit The rule list is limited to 30 KB. Depending on the average length of the IP addresses or ranges, you can configure approximately 700 IPv6 addresses/ranges or 2,000 IPv4 addresses/ranges. To block more IPs than this limit allows, activate Edge Security Acceleration (ESA), which supports massive IP blocking and regional blocking. For more information, see Upgrade from CDN or DCDN to ESA and Configure IP access rules. |
IP Rules | Choose one of the following three rules:
|
Rule Condition | Rule conditions can identify parameters in a request to determine whether a configuration applies to the request.
|
Reference: How Alibaba Cloud CDN identifies client IP addresses
CDN POPs can identify client IP addresses in two ways. Each method has its advantages and disadvantages:
Real connection IP address (TCP connection IP)
Definition: The IP address used by the client to establish a TCP connection with the CDN POP.
Advantage: Cannot be spoofed, providing the highest level of security.
Disadvantage: When a user accesses through a proxy (such as a corporate network gateway or NAT device), this IP address is the proxy server's, not the client's.
X-Forwarded-For(XFF) request headerDefinition: An HTTP header field used to record the IP address of each proxy server a request passes through. The CDN typically uses the leftmost IP in this header as the client IP.
Advantage: Can bypass proxies to get the client's real IP address.
Disadvantage: A client can easily forge this header, posing a significant security risk. Malicious users can bypass IP-based access controls by spoofing the XFF header.
When a client accesses CDN directly, these two IP addresses are the same. However, if the client accesses CDN through a proxy server, the IP addresses are different. For example, if the originating IP address of the client is 10.10.10.10 and the IP address of the proxy server is 192.168.0.1, then:
The value of the
X-Forwarded-Forheader might be10.10.10.10, 192.168.0.1.The originating IP address of the client is
10.10.10.10.The TCP connection IP address is
192.168.0.1.
To balance security and business flexibility, CDN provides three verification modes based on these IP identification methods.
IP address validation mode | Use case | How it works | Security |
Determine based on the XFF header (Default) | Clients access through a trusted proxy that correctly sets the XFF header. | Extracts and matches only the leftmost IP address in the | Low. Clients can forge the |
Determine based on the IP address that is used to connect to the POP | Clients connect directly to the CDN without a proxy, or you want to control access based on proxy server IPs. | Matches only the IP address used to establish the TCP connection between the client and the CDN POP. | High. The TCP Connection IP cannot be spoofed, providing the most reliable protection. |
Determine based on the XFF header and the IP address that is used to connect to the POP | Mixed network environments where some users connect directly and others use a proxy. | Blacklist: The request is blocked if either the IP in the | Medium to high. This mode balances flexibility with security, making it a robust choice for most scenarios. |
FAQ
Related API operations
Add an IP Blacklist or Whitelist configuration
Call the BatchSetCdnDomainConfig operation to configure an IP Blacklist/Whitelist. For parameters details, see Configure IP Whitelist and Configure IP Blacklist.
Update an IP Blacklist or Whitelist configuration
Call the BatchSetCdnDomainConfig operation to update the IP Blacklist or Whitelist. For more information about the related parameters, see Configure IP Whitelist and Configure IP Blacklist.
This operation updates only the parameters included in the request. For example, if you pass the ip_list parameter but not the ip_acl_xfwd parameter, ip_acl_xfwd will not be updated.
This operation only supports updating the IP list, IP rule, and rule condition. You cannot change the configuration type. For example, you cannot use this operation to change a blacklist to a whitelist.
To change the configuration type, for example, from an IP blacklist to an IP whitelist, you must perform the following steps:
Call the delete operation to remove the existing IP blacklist configuration.
Call the add operation to add the new IP whitelist configuration.
Delete an IP Blacklist or Whitelist configuration
Step 1: Query the ConfigId
Call the DescribeDomainConfigs operation to query the ConfigId of the configuration. If you already know the ConfigId, skip this step.
Step 2: Delete the configuration
Call the BatchSetCdnDomainConfig operation and use the ConfigId to delete the configuration.