Access control
Access control (called Hotlink protection settings (防盗链配置) in the console) restricts who can anonymously access public files in a bucket. For example, you can allow only your own website to embed images, or block certain clients and IPs.
To get there, go to Object Storage (对象存储) › Bucket list (桶列表) › click the bucket name › Access management (访问管理) › Hotlink protection settings.
Scope
| Request | Checked |
|---|---|
| Anonymous access to the bucket default domain or a bound bucket domain | Yes |
| Presigned URLs and requests signed with an AccessKey | No |
| Access through a CDN domain | No. Set access control on the CDN |
- When Referer, Headers, and IP are all set, a request must pass all of them to be allowed.
- A request that fails returns
403 AccessDenied. - Changes take effect immediately after you save.
- These rules don't make private files accessible. Files still need to be made public first.
Referer and request headers are filled in by the client. They suit preventing hotlinking between websites but can't replace authentication. For strict restrictions, keep files private and use presigned URLs, or the CDN's advanced authentication.
Referer
Click Edit (编辑) on the Referer card.
Whether to allow requests that have no Referer. Opening a file directly in the address bar, and some apps and download tools, send no Referer, and turning this off rejects all of them.
Allowlist active: Only sources that match the list can access. Blocklist active: Sources that match the list are rejected. You can't use both at the same time, and saving one replaces the other.
One domain or IP per line. The content (including wildcard expansion) can't exceed 1 KiB, and you're warned before saving if it does.
How matching works:
- Matching starts from the beginning of the Referer and is case-insensitive.
- If you don't write
http://orhttps://, both protocols match. If you write one, only that protocol matches. *matches any number of characters, and?matches one character.
| Rule | Matches | Doesn't match |
|---|---|---|
www.example.com/ | https://www.example.com/page | https://example.com/ |
example.com/ | https://example.com/, http://example.com/a | https://www.example.com/ |
*.example.com/ | https://www.example.com/, https://a.b.example.com/ | https://example.com/ |
https://example.com/blog/ | https://example.com/blog/1.html | https://example.com/ |
- Rules that contain only a domain (such as
example.comor*.example.com) get a trailing/automatically when saved, so they don't match domains likeexample.com.evil.com. For origins with a port, include the port, for exampleexample.com:8080. - If you really need prefix matching, end the rule with
*. Rules saved earlier are completed only when you edit and save them again. - Write the root domain and
*.subdomains on separate lines. - Many browsers send only the origin domain, without the path, on cross-site requests, so we don't recommend allowlisting by path.
When the allowlist is empty, you see "系统会拒绝携带任何Referer的匿名请求" (the system will reject anonymous requests that carry any Referer) before saving.
To remove the restriction: choose Blocklist active, clear the list, set Empty Referer to On (access allowed), then save.
Headers
Restrict access by any request header. The most common is User-Agent. Each header is set separately, up to 10 per bucket.
Case-insensitive; letters, digits, hyphens, and underscores only; up to 29 characters; can't be renamed after creation. Set Referer on the Referer card. Host, Authorization, Transfer-Encoding, and Trailer aren't supported.
Allowlist: A request must match at least one entry to access. Blocklist: A request that matches any entry is rejected.
One per line, compared with the entire value of the request header, case-insensitive. * matches any number of characters and ? matches one character; escaping isn't supported. Rules for the same header total at most 1024 bytes, and each wildcard counts as 3 bytes. Consecutive ? aren't allowed.
Unlike Referer, Headers match the entire string: to match "contains Chrome", write *Chrome*.
Examples:
| Goal | Header | Type | Empty value | Rules |
|---|---|---|---|---|
| Block common command-line downloaders | User-Agent | Blocklist | Deny access | *curl*, *wget*, *python* |
| Allow only your own app | User-Agent | Allowlist | Deny access | MyApp/* |
| Allow cross-origin requests only from a specific site | Origin | Allowlist | Allow access | https://www.example.com |
Two special cases:
- An empty allowlist that doesn't allow empty values rejects all anonymous requests, and you must confirm before saving.
- An empty blocklist that allows empty values is the same as no restriction and can't be saved. Add rules or delete this header.
IP
Click Edit on the IP card.
Allowlist active: Only IPs in the list are allowed. Blocklist active: IPs in the list are rejected. You can't use both at the same time.
One per line. Single IPv4 addresses and CIDR ranges (mask /1 ~ /32) are supported, for example 114.114.114.114 and 114.114.114.0/24. All content together can't exceed 1024 bytes, about 60 addresses, so merge addresses into ranges where you can.
When the allowlist is empty, you see "系统会拒绝来自任何IP的匿名请求" (the system will reject anonymous requests from any IP) before saving. To remove the restriction, choose Blocklist active, clear the list, and save.
FAQ
My own website's images won't load after I set this up
- Use the browser's developer tools to check the Referer of the image request and confirm it matches the allowlist.
- If the page sets
Referrer-Policy: no-referrerorrel="noreferrer", no Referer is sent, and you need to allow empty Referers. - If your site has both
wwwand non-wwwdomains, add both.
It won't open in WeChat or an app
These environments may not send a Referer. Allow empty Referers, or switch to signed links.
Saving shows "设置referer失败" or "设置IP失败"
These mean "failed to set Referer" or "failed to set IP". Most often the content exceeds 1024 bytes. Reduce the entries, or merge them with wildcards or ranges.
I already use a CDN. Do I still need to set this?
Access through the CDN domain isn't subject to the rules here. Set them on the CDN. Anonymous access to the bucket default domain is still subject to the rules here.