Last active
January 26, 2023 16:18
-
-
Save kiranvj/17b3264b2d53e83d7c5cd024ccd1a134 to your computer and use it in GitHub Desktop.
AWS S3 bucket policy for public access and disabling hotlinking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", // SOME VERSION | |
"Id": "", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::BUCKET-NAME/FOLDER-NAME/*" | |
}, | |
{ | |
"Sid": "Allow in my domains", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "*" | |
}, | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::BUCKET-NAME/*", | |
"Condition": { | |
"StringLike": { | |
"aws:Referer": [ | |
"https://YOUR-DOMAIN.com/*", | |
"https://www.YOUR-DOMAIN.com/*", | |
"http://localhost:3000/*" // FOR LOCAL TESTING | |
] | |
} | |
} | |
}, | |
{ | |
"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": [ | |
"https://YOUR-DOMAIN.com/*", | |
"https://www.YOUR-DOMAIN.com/*", | |
"http://localhost:3000/*" // FOR LOCAL TESTING | |
] | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment