Skip to content
Console

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

RequestChecked
Anonymous access to the bucket default domain or a bound bucket domainYes
Presigned URLs and requests signed with an AccessKeyNo
Access through a CDN domainNo. 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.

Empty Referersingle choiceDefault On (access allowed)

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.

Referer allowlist / blocklistmultiline text

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:// or https://, both protocols match. If you write one, only that protocol matches.
  • * matches any number of characters, and ? matches one character.
RuleMatchesDoesn't match
www.example.com/https://www.example.com/pagehttps://example.com/
example.com/https://example.com/, http://example.com/ahttps://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.htmlhttps://example.com/
  • Rules that contain only a domain (such as example.com or *.example.com) get a trailing / automatically when saved, so they don't match domains like example.com.evil.com. For origins with a port, include the port, for example example.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.

Add

Click Add Header (添加 Header) on the Headers card.

Fill in the rule

Fill in the fields below, then enter a request header value in Test (测试) to confirm whether it is allowed or rejected.

Save

Click Save (保存). Manage existing headers with Edit and Delete (删除).

Header nametextRequired

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.

Typesingle choiceDefault Blocklist

Allowlist: A request must match at least one entry to access. Blocklist: A request that matches any entry is rejected.

Empty valuesingle choiceDefault Allow access

Whether to allow requests that don't carry this header or whose value is empty.

Rulesmultiline text

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:

GoalHeaderTypeEmpty valueRules
Block common command-line downloadersUser-AgentBlocklistDeny access*curl*, *wget*, *python*
Allow only your own appUser-AgentAllowlistDeny accessMyApp/*
Allow cross-origin requests only from a specific siteOriginAllowlistAllow accesshttps://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.

IP allowlist / blocklistmultiline text

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
  1. Use the browser's developer tools to check the Referer of the image request and confirm it matches the allowlist.
  2. If the page sets Referrer-Policy: no-referrer or rel="noreferrer", no Referer is sent, and you need to allow empty Referers.
  3. If your site has both www and non-www domains, 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.