I’m trying to implement a way for users to upload profile pictures to their profiles on my website. The solution I’ve landed on is having S3 to store the images with CloudFront serving the images. Firstly, is this a good solution?
As for how it gets done: I am using VueJS to create a single-page app on the front end, and Django as my back end server. Should I allow users to upload directly to S3 using presigned urls, or should the image first go through my server, then to S3 from there? What are the security concerns and drawbacks of each way? Please help, and if there’s a better way to do what I’m trying to do, please let me know.
On the content serving side using s3 and cloudfront together is extremely standard.
On the upload side you should not generate presigned URLs on the client. These require YOUR security credentials as well as bucket name and key. These should only be available through environmental variables on your server.
So I would recommend posting the image to your server first and then uploading it to S3 from there, generating a URL for later access, and then storing that in a db.
I partially agree. Presigned Urls should be generated in the backend, but I would lift the uploading to the client and release some burden from the server.
So the client should do 2 request one after another:
One to gather the url from the backend and another to upload the file using the url.
I agree with the signed urls but do you need protection against a user uploading arbitrary files to s3? Do you need to check the max file size or scan it for porn etc?
Basically if somebody’s credentials are leaked, how worried are you about how much damage they could do?
Your approach is correct. Generate non-colliding file names server side along with the presigned url and provide it to the client. The urls expire, so set an appropriate timeframe.
I use presigned URLs too, I have users uploading large files, so if those went through the backend, it would clog up pretty quickly. I also use presigned get URLs to actually display the images, so I don’t even have to worry about Cloudfront sync or anything. Imho it’s pretty safe.