简体   繁体   English

使用链接到网页上的AWS S3存储桶中的图像是否安全?

[英]Is it safe to use a link to an image in my AWS S3 bucket on my webpage?

I have an image in my AWS S3 bucket. 我的AWS S3存储桶中有一个映像。 Is it safe to include this image in my website by placing the AWS URL in an <img> tag? 通过将AWS URL放在<img>标记中将此图像包含在我的网站中是否安全? The URL includes parameters such as "Amz-Signature", "Amz-Credential", and "amz-security-token. Could these be used maliciously to get to access other files in my S3 bucket? 该URL包含“ Amz-Signature”,“ Amz-Credential”和“ amz-security-token”之类的参数。是否可以恶意使用这些参数来访问S3存储桶中的其他文件?

Here is an example URL: 这是一个示例URL:

https://s3.amazonaws.com/MyBucketName/FileName.jpg?X-Amz-Date=20160126T141139Z&X-Amz-Expires=300&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=Lots_of_letters_and_Numbers2&X-Amz-Credential=MYAMAZON_CREDENTIALS/20160126/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=Host&x-amz-security-token=REALLY_LONG_SECURITYTOKEN

Alternatively, I can generate an expiry URL from my C# code using the AWS SDK. 另外,我可以使用AWS开发工具包从C#代码生成到期URL。 Something like: 就像是:

var expiryUrlRequest = new GetPreSignedUrlRequest
{
    BucketName = WebConfigurationManager.AppSettings["AWSBucketName"],
    Key = fileName,
    Expires = DateTime.Now.AddHours(3)
};

This yields a URL that has "AWSAccessKeyId" as a parameter. 这将产生一个以“ AWSAccessKeyId”作为参数的URL。

Are either of these URL's safe to use in my webpage? 这些网址中的任何一个都可以安全使用吗? What risks would be involved in using them on my site? 在我的网站上使用它们会涉及哪些风险?

Thank you very much for your time. 非常感谢您的宝贵时间。 Please let me know if you need additional information or if I am being unclear. 如果您需要其他信息或不清楚,请告诉我。

EDIT: To provide some further insight into my application, users are uploading a file to an S3 bucket. 编辑:为了提供对我的应用程序的进一步了解,用户正在将文件上传到S3存储桶。 I'm using SignalR to confirm that the image is in the bucket by displaying the image from S3 on my webpage for the user to see. 我正在使用SignalR通过在我的网页上显示S3中的图像以供用户查看来确认图像是否在存储桶中。

Do not make the bucket public. 不要公开存储桶。 If you do, then potentially user1 could see user2's uploaded files. 如果这样做,则user1可能会看到user2的上传文件。

You can allow users to retrieve single files for a specific period of time using pre-signed URLs. 您可以允许用户使用预先签名的URL在特定时间段内检索单个文件。

  1. Mark the S3 bucket as private. 将S3存储桶标记为私有。
  2. Use GetPreSignedUrlRequest to generate a pre-signed URL for the file you want the user to download. 使用GetPreSignedUrlRequest为您希望用户下载的文件生成一个预签名的URL。
  3. Use that URL in your <img> tag. <img>标记中使用该URL。

Using this technique is safe: 使用此技术是安全的:

  1. The user can only download the file during the timeframe that you permit, until the expiration date (which you set as part of the GetPreSignedUrlRequest call) 用户只能在您允许的时间范围内下载文件,直到到期日期(您将其设置为GetPreSignedUrlRequest调用的一部分)
  2. The credentials you see in the URL are may be the same as those that were used to create the URL. 您在URL中看到的凭据可能与用于创建URL的凭据相同。 But they are safe to show the user. 但是可以安全地向用户显示。
  3. The user cannot download any other files from the bucket. 用户无法从存储桶下载任何其他文件。

The URL uses a hashing technique to ensure the URL cannot be modified, nor can it be abused to get other files. URL使用哈希技术来确保URL不能被修改,也不能被滥用以获取其他文件。

If displaying the access key ID is a concern, you can either (a) create an IAM user specifically for the purpose of downloading the files from S3, or (b) use an IAM role on your EC2 instance to generate the pre-signed URL. 如果需要显示访问密钥ID,则可以(a)创建一个IAM用户专门用于从S3下载文件,或者(b)在您的EC2实例上使用IAM角色来生成预签名的URL 。

References: 参考文献:

First of all, there are two ways of restricting access to the content of a bucket: 首先,有两种限制访问存储桶内容的方法:

If you want other users to access the image (for example by providing a URL for your website), you should mark the bucket as public. 如果您希望其他用户访问该图像(例如,通过提供您网站的URL),则应将存储桶标记为公共。

DO NOT post the url with your AWS credentials anywhere!!! 不要在任何地方使用您的AWS凭证发布URL!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM