Skip to content

Instantly share code, notes, and snippets.

@mikesprague
Last active November 25, 2022 18:24
Show Gist options
  • Save mikesprague/5881937 to your computer and use it in GitHub Desktop.
Save mikesprague/5881937 to your computer and use it in GitHub Desktop.
AWS: Bucket Policy Example (Allow Get by Referer)
{
"Version": "2008-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests from certain domains (including local development)",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name-here/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://sub1.domain.com/*",
"https://sub1.domain.com/*",
"http://domain.com/*",
"https://*.domain.dev/*",
"https://*.domain.com/*",
"http://sub1.domain.dev/*",
"https://sub1.domain.dev/*",
"https://domain.com/*",
"http://s3.amazonaws.com/*",
"http://*.domain.com/*",
"http://app-name.herokuapp.com/*",
"https://app-name.herokuapp.com/*",
"https://s3.amazonaws.com/*",
"http://*.domain.dev/*",
"http://localhost*/*",
"http://localhost:*/*",
"https://localhost*/*",
"https://localhost:*/*"
]
}
}
}
]
}
@KarthikEK20
Copy link

How can i set referrer property when i use the bucket download URL from Xamarin mobile app?
I have used below snippet, but it not set the referrer, getting forbidden error.
string downloadFilePath = "https://s3.amazonaws.com/test-website-content/downloads/jQuery_Succinctly.pdf";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(downloadFilePath);
httpWebRequest.Referer="http://localhost";
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

Please help me to resolve this,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment