开发者

Amazon S3 Browser Based Upload - Prevent Overwrites

开发者 https://www.devze.com 2023-01-08 10:05 出处:网络
We are using Amazon S3 for images on our website and users upload the images/files directly to S3 through our website.In our policy file we ensure it \"begins-with\" \"upload/\".Anyone is able to see

We are using Amazon S3 for images on our website and users upload the images/files directly to S3 through our website. In our policy file we ensure it "begins-with" "upload/". Anyone is able to see the f开发者_如何转开发ull urls of these images since they are publicly readable images after they are uploaded. Could a hacker come in and use the policy data in the javascript and the url of the image to overwrite these images with their data? I see no way to prevent overwrites after uploading once. The only solution I've seen is to copy/rename the file to a folder that is not publicly writeable but that requires downloading the image then uploading it again to S3 (since Amazon can't really rename in place)


If I understood you correctly The images are uploaded to Amazon S3 storage via your server application. So the Amazon S3 write permission has only your application. Clients can upload images only throw your application (which will store them on S3). Hacker can only force your application to upload image with same name and rewrite the original one.

How do you handle the situation when user upload a image with a name that already exists in your S3 storage? Consider following actions:

  1. First user upload a image some-name.jpg
  2. Your app stores that image in S3 under name upload-some-name.jpg
  3. Second user upload a image some-name.jpg
  4. Will your application overwrite the original one stored in S3?


I think the question implies the content goes directly through to S3 from the browser, using a policy file supplied by the server. If that policy file has set an expiration, for example, one day in the future, then the policy becomes invalid after that. Additionally, you can set a starts-with condition on the writeable path.

So the only way a hacker could use your policy files to maliciously overwrite files is to get a new policy file, and then overwrite files only in the path specified. But by that point, you will have had the chance to refuse to provide the policy file, since I assume that is something that happens after authenticating your users.

So in short, I don't see a danger here if you are handing out properly constructed policy files and authenticating users before doing so. No need for making copies of stuff.


actually S3 does have a copy feature that works great

Copying Amazon S3 Objects

but as amra stated above, doubling your space by copying sounds inefficient
mybe itll be better to give the object some kind of unique id like a guid and set additional user metadata that begin with "x-amz-meta-" for some more information on the object, like the user that uploaded it, display name, etc...
on the other hand you could always check if the key exists already and prompt for an error

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号