Object Storage Service (OSS) allows you to configure Referer
-based access control policies, such as policies for Referer
whitelisting and blacklisting. You can also specify whether requests with empty referrers are allowed. This way, you can prevent unauthorized access and unexpected traffic fees.
Usage notes
Before you configure hotlink protection, familiarize yourself with this feature. For more information, see hotlink protection.
The sample code in this topic uses the region ID
cn-hangzhou
of the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket by using other Alibaba Cloud services in the same region in which the bucket is located, use an internal endpoint. For more information about the regions and endpoints supported by Object Storage Service (OSS), see OSS regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
To configure hotlink protection for a bucket or delete the hotlink protection configurations of a bucket, you must have the
oss:PutBucketReferer
permission. To query the hotlink protection configurations, you must have theoss:GetBucketReferer
permission. For more information, see Grant custom permissions to RAM users.
Sample code
References
For more information about the API operation that you can call to configure hotlink protection for a bucket, see PutBucketReferer.
For more information about the API operation that you can call to query the configurations of hotlink protection, see GetBucketReferer.