Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

Hiding file source in an S3 bucket


I'm running an S3 bucket with a Cloudfront distribution. Everything works except the ability to read the source code is still there.

So the bucket is at mybucket.domain.com and that works okay. However, navigating to mybucket.domain.com/script.js or mybucket.domain.com/style.css will reveal the contents of each file.

I have searched far and wide for a solution but seem to be coming up blank every time. I've tried things with the bucket policy and Cloudfront settings to no avail. Any thoughts are appreciated. Thanks.


Solution

  • There's no way to prevent this. The web browser has to be able to download those files to the local computer in order to render your website. In order for the web browser to download those files they have to be publicly available. There's no way to stop someone from viewing the source of files that are publicly available. Since there are copies of these files on every computer that has visited your website, there is absolutely no way to keep people from viewing the source of those files.

    You shouldn't place anything in those files that shouldn't be publicly available.