AWS S3 : Prevent Hotlinking policy
Problem :
Hosting a lot of photos or video files on AWS S3? Don't want other websites to link to your content or use your S3 as a free loader?
Solution :
Add new bucket policy to prevent hot linking. Go to the properties of the S3 bucket you want to prevent hot linking policy and click on the Add Bucket Policy button.
A modal box will appear and enter this policy :
{
"Version": "2008-10-17",
"Id": "preventHotLinking",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-s3-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://yourwebsitename.com/*",
"http://www.yourwebsitename.com/*"
]
}
}
}
]
}
NOTE : Change your-s3-bucket and yourwebsitename.com to yours.
Reference :
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
See also : WARNING: UNPROTECTED PRIVATE KEY FILE! error message
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8k Prevent Write failed: Broken pipe problem during ssh session with screen command
+17.5k Golang : Iterate linked list example
+9.1k Golang : How to get username from email address
+5.4k Unix/Linux : How to find out the hard disk size?
+14.5k Golang : Normalize unicode strings for comparison purpose
+7.2k Golang : Check to see if *File is a file or directory
+12.4k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+8.9k Golang : Simple histogram example
+18.5k Golang : Display list of time zones with GMT
+4.6k PHP : Extract part of a string starting from the middle
+11.5k Golang : Gorilla web tool kit secure cookie example
+7.6k Javascript : How to check a browser's Do Not Track status?