Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent hotlinking on Amazon S3 without using signed URLs?

Tags:

Is there any way I can prevent hotlinking on Amazon S3 without using signed URLs?

like image 502
MathOldTimer Avatar asked Jun 04 '09 06:06

MathOldTimer


People also ask

How do I protect my S3 bucket from unauthorized usage?

The easiest way to secure your bucket is by using the AWS Management Console. First select a bucket and click the Properties option within the Actions drop down box. Now select the Permissions tab of the Properties panel. Verify that there is no grant for Everyone or Authenticated Users.

How do I mask my Amazon S3 URL?

There are two parts to masking your S3 url, the first is creating and naming a bucket in S3 to match the subdomain, the second is creating the subdomain and pointing it to the S3 bucket url.


2 Answers

You need a bucket policy that both allows referrers from your domain(s) and denies referrers who are not from your domains. I've found that images can be hotlinked if you don't include the explicit denial - many guides and examples just give the allow policy and don't mention the deny part.

Here's my policy, just change BUCKET-NAME and YOUR-WEBSITE to your own details:

{   "Version": "2008-10-17",   "Id": "",   "Statement": [     {       "Sid": "Allow in my domains",       "Effect": "Allow",       "Principal": {         "AWS": "*"       },       "Action": "s3:GetObject",       "Resource": "arn:aws:s3:::BUCKET-NAME/*",       "Condition": {         "StringLike": {           "aws:Referer": [             "http://www.YOUR-WEBSITE.com/*"           ]         }       }     },     {       "Sid": "Deny access if referer is not my sites",       "Effect": "Deny",       "Principal": {         "AWS": "*"       },       "Action": "s3:GetObject",       "Resource": "arn:aws:s3:::BUCKET-NAME/*",       "Condition": {         "StringNotLike": {           "aws:Referer": [             "http://www.YOUR-WEBSITE.com/*"           ]         }       }     }   ] } 
like image 148
Ollie Glass Avatar answered Oct 15 '22 23:10

Ollie Glass


By setting up the right S3 bucket policy, you can add referral policy to prevent the hotlink.

http://s3browser.com/working-with-amazon-s3-bucket-policies.php

like image 27
Robert Mao Avatar answered Oct 15 '22 22:10

Robert Mao