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.
When you add a domain name like
aliyundoc.comto a Referer list, CDN apply the rule to both the domain itself and all its subdomains (such as*.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.aliyun.comto the Referer whitelist to preview videos in the ApsaraVideo VOD console.
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 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 deny the request.
If the Referer in a request matches an entry in the whitelist, CDN allow the request.
Procedure
Log in to the ApsaraVideo VOD console.
In the left-side navigation pane, 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
The POP denies access to requests that contain a Referer from the blacklist.
Whitelist
The POP allows only requests that contain a Referer from the whitelist.
NoteBlacklists and whitelists are mutually exclusive. You can select only one type at a time.
Rules
You can add multiple Referers. Separate each entry with a line break.
You can use an asterisk (*) as a wildcard to match all subdomains. For example,
*.example.commatches all subdomains ofexample.com.If you do not specify a wildcard, an entry matches both the domain itself and all its subdomains. For example, an entry for
example.commatches bothexample.comand*.example.com.
NoteThe total size of all rules in a Referer list cannot exceed 60 KB.
You do not need to include the scheme in the rules.
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
http://orhttps://. Example:http://www.example.com.Advanced
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.
The request does not include a Referer header.
The Referer header 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 the Ignore Scheme option is cleared, the Referer header must include an HTTP or HTTPS scheme.
If you select the Ignore Scheme option, the Referer header is not required to include a scheme.
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. |