Referer-based hotlink protection uses the Referer field in HTTP request headers—such as a Referer whitelist or blacklist—to enforce access control. It identifies and filters visitors to prevent unauthorized use of your website resources. After you configure a Referer whitelist or blacklist, CDN checks each request against the list and either allows or denies access. If allowed, CDN returns the resource URL. If denied, CDN returns HTTP status code 403. This topic describes how to configure Referer hotlink protection.
In ApsaraVideo VOD, Referer hotlink protection is disabled by default. This means any website can access your resources.
After you add a domain name to the Referer blacklist or whitelist, the wildcard domain name that matches the domain name is automatically added to the blacklist or whitelist. For example, if you add
aliyundoc.comto the Referer blacklist or whitelist, it takes effect for all domain names that match*.aliyundoc.com.For Range requests, browsers add the Referer header on the second request. To allow these requests, add the domain to the Referer whitelist.
After enabling Referer hotlink protection in ApsaraVideo VOD, add
vod.console.alibabacloud.comto the Referer whitelist to preview videos in the ApsaraVideo VOD console.
Referer structure
The Referer header is a component of the header section in HTTP requests and contains information about the source address and is used to identify the source of a request. The Referer header consists of the scheme, domain, path, and parameters. The following figure describes the structure of the Referer header.
The protocol and domain name are required, and the path and query parameters are optional.
Alibaba Cloud allows you to specify only domain names as Referers by selecting Ignore Scheme.
Scenarios
A Referer blacklist or whitelist is suitable for the following scenarios:
Copyright protection: To safeguard copyrighted content on your website, you can use a Referer blacklist or whitelist to allow only authorized websites to access the content.
Hotlink protection: Referer whitelists or blacklists can prevent your resources from being used by other websites.
Enhanced website security: Only domain names that are included in the Referer whitelist are allowed to access your website resources. This prevents malicious hotlinking or theft of sensitive information.
Traffic source management: You can manage the domains that are authorized to use your resources. This ensures the security and stability of your website.
You can use the feature in different scenarios to protect your website assets, manage traffic, and improve website security.
How it works
The server checks the Referer field of each request and rejects a request if the Referer field in the request does not match the pre-configured whitelist. This helps save bandwidth and server resources. Referer rules in Alibaba Cloud CDN:
If the Referer header in the request is included in the Referer blacklist or is not included in the Referer whitelist, Alibaba Cloud CDN rejects the request.
If the Referer header in the request is included in the Referer whitelist, Alibaba Cloud CDN allows the request.
Procedure
Log on to the ApsaraVideo VOD console.
In the navigation pane on the left, under Configuration Management, click CDN Configuration > Domain Names.
On the Domain Names page, find the target domain name. Click Actions, then click Configure.
In the navigation pane on the left for that domain, click Resource Access Control.
On the Referer Hotlink Protection tab, click Modify.
Select Blacklist or Whitelist as needed.
Parameter
Description
Type
Blacklist
Requests whose Referer field is in the Referer blacklist cannot access the resources.
Whitelist
Only requests whose Referer field is in the Referer whitelist can access the resources.
NoteThe whitelist and blacklist are mutually exclusive. You can configure only one of the lists.
Rules
You can add multiple domain names to the Referer blacklist or whitelist. Separate domain names with carriage return characters.
You can use asterisks (*) as wildcards to match all domain names. For example,
*.example.commatches all subdomains ofexample.com.You can also omit the asterisk (*) to match the domain and its all subdomains. For example,
example.commatchesexample.comand*.example.com.
NoteThe content that you enter in the Rules field cannot exceed 60 KB.
You do not need to specify the protocol when you configure rules.
Redirect URL
If a request is blocked, HTTP status code 302 and the Location header are returned. This parameter is the value of the Location header. The value must start with
http://orhttps://, such ashttp://www.example.com.Advanced
Allow resource URL access from browsers
By default, the check box is not selected. If you select the check box, requests that contain an empty Referer header are allowed to access CDN resources, regardless of whether you configure a Referer blacklist or whitelist.
The Referer header is not included in the requests.
The Referer header is included, but the value is empty.
Exact match
By default, this option is not selected. If selected, wildcards (*) are no longer supported for domain matching. For example,
example.commatches onlyexample.com—not its subdomains.Ignore scheme
If you do not select Ignore Scheme, the value of the Referer header must start with http:// or https://.
If you select Ignore Scheme, the value of the Referer header does not need to start with http:// or https://.
Click OK to complete the configuration.
Referer matching logic
The table below shows how Referer matching works. If a request does not match the whitelist—or matches the blacklist—CDN rejects the request and returns HTTP status code 403.
List configuration | Referer in request | Match result | Matching logic |
| http://www.example.com/img.jpg | Yes | The domain in the Referer header matches an entry in the rule list. |
http://www.example.com:80/img.jpg | Yes | ||
www.example.com | For more information, see the description of the matching logic. |
| |
http://aaa.example.com | Yes | Result is Yes regardless of whether Exact match is selected. | |
http://aaa.bbb.example.com | See explanation |
| |
http://example.com | No | The second-level domain in the Referer header does not match the wildcard entry. Wildcard entries do not include the second-level domain itself. | |
http://www.example.net | No match | The request matches neither the whitelist nor the blacklist. By default, access is allowed. |