Skip to content

Instantly share code, notes, and snippets.

@kiranvj
Last active January 26, 2023 16:18
Show Gist options
  • Save kiranvj/17b3264b2d53e83d7c5cd024ccd1a134 to your computer and use it in GitHub Desktop.
Save kiranvj/17b3264b2d53e83d7c5cd024ccd1a134 to your computer and use it in GitHub Desktop.
AWS S3 bucket policy for public access and disabling hotlinking
{
"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