A Referer blacklist or whitelist controls access to your resources based on the Referer header of HTTP requests. This feature prevents hotlinking and unauthorized resource use. Once configured, CDN and evaluate the Referer header to grant or deny access.
-
By default, the Referer blacklist/whitelist feature for Alibaba Cloud CDN and is disabled, allowing any website to access your resources.
-
Referer blacklists and whitelists are one way to prevent hotlinking. For more methods, see Best practices for preventing hotlinking.
-
When you add a domain name like
aliyundoc.comto a Referer list, CDN and apply the rule to both the domain itself and all its subdomains (such as*.aliyundoc.com).
Anatomy of a Referer
The Referer header indicates the URL of the page where a request originated. A Referer URL consists of a scheme, domain, path, and query parameters, as shown in the following figure.
-
The value of a Referer header is essentially a URL.
-
Alibaba Cloud supports domain-only Referer configurations. To enable this, select the Ignore Scheme option.
Use cases
A Referer blacklist or whitelist primarily protects your website resources from being directly linked or used by other websites. Common use cases include:
-
Copyright protection: For websites with copyrighted content, you can use a Referer whitelist to restrict access to authorized websites only.
-
Hotlinking prevention: A whitelist ensures that your resources can be accessed only from specific websites, preventing other sites from consuming your bandwidth by directly linking to your content.
-
Enhanced website security: By allowing only specific websites to access your resources, you can prevent malicious hotlinking, unauthorized access, and theft of sensitive information.
-
Traffic source control: You can restrict traffic from specific websites to control traffic sources and improve the stability and security of your website.
How it works
A Point of Presence (POP) checks the Referer header of each request. If the Referer is not on the whitelist or if it is on the blacklist, the POP denies the request. This saves bandwidth and reduces load on the origin server. CDN and use the following rules to process Referer requests:
-
If the Referer in a request matches an entry in the blacklist or does not match any entry in the whitelist, CDN and deny the request.
-
If the Referer in a request matches an entry in the whitelist, CDN and allow the request.
Usage notes
-
After you configure a Referer blacklist, requests from blacklisted sources can still reach CDN and POPs. However, these requests are rejected with a 403 status code and are recorded in CDN and logs.
-
The Referer blacklist/whitelist feature enforces access control based on the Referer header in an HTTP request. Blocking requests incurs a small fee for the generated traffic. For HTTPS, you are also charged per request.
-
Because CDN hotlinking originates from public network access, Referer rules apply only to public domain names.
Procedure
-
Log on to the CDN console.
-
In the left navigation pane, click Domain Names.
-
On the Domain Names page, find the target domain name and click Manage in the Actions column.
-
In the domain's navigation pane, click Access Control.
-
On the Referer Black/Whitelist tab, click Modify.
-
Configure the Referer parameters. For more information, see Referer configuration parameters.
-
Click OK to save the configuration.
Referer configuration parameters
|
Parameter |
Description |
|
|
Type |
Note
Blacklists and whitelists are mutually exclusive. You can select only one type at a time. |
|
|
Rules |
Note
|
|
|
Redirect URL |
If a request is blocked, the POP returns a 302 redirect with a Location response header. This parameter specifies the value for the Location header. The URL must start with |
|
|
Advanced Settings |
Allow resource URL access from browsers |
This option is cleared by default. If you select this option, requests with an empty referer are not blocked and are allowed to access the resource, regardless of your list settings. An empty referer is defined as either of the following:
|
|
Exact Match |
This option is cleared by default. If you select this option, the default behavior of matching subdomains is disabled. If you do not use a wildcard, an entry such as |
|
|
Ignore Scheme |
|
|
|
Rule Condition |
A rule condition allows a rule to be applied only when a request meets specific criteria. Important
When a feature references rule conditions, the execution order follows the priority of the associated rule conditions, not the order of the feature configurations.
|
|
Configuration verification
You can use the curl command to test your configuration. Use the -e option to specify the referer value and the -I option to retrieve only the response headers of the accelerated domain name. The following examples use a whitelist for verification.