Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 createPresignedPost vs getSignedUrl. Which one should I use for uploading various files from client side?

On S3 document, there is createPresignedPost and getSignedUrl.

On getSignedUrl:

Note: Not all operation parameters are supported when using pre-signed URLs. Certain parameters, such as SSECustomerKey, ACL, Expires, ContentLength, or Tagging must be provided as headers when sending a request. If you are using pre-signed URLs to upload from a browser and need to use these fields, see createPresignedPost().

Is createPresignedPost simply more customizable version of getSignedUrl? Is it doing the same thing underneath?

like image 971
Joon Avatar asked Oct 04 '18 22:10

Joon


People also ask

What is the main advantage to a pre-signed URL?

A presigned URL gives you access to the object identified in the URL, provided that the creator of the presigned URL has permissions to access that object.

When should I use Presigned URL S3?

Pre-signed URLs are used to provide short-term access to a private object in your S3 bucket. They work by appending an AWS Access Key, expiration time, and Sigv4 signature as query parameters to the S3 object. There are two common use cases when you may want to use them: Simple, occasional sharing of private files.

What is the difference between put and post in AWS S3?

POST is an alternate form of PUT that enables browser-based uploads as a way of putting objects in buckets. Parameters that are passed to PUT through HTTP Headers are instead passed as form fields to POST in the multipart/form-data encoded message body.

Are pre-signed URL safe?

Anyone can use a valid presigned URL Just to make sure this is clear: if you generate a presigned URL anyone can use this, the user generating this link could use it to phish another user and let them upload an arbitrary file. So be sure you threat model properly your feature to avoid logic vulnerabilities.


1 Answers

If you want to restrict users from uploading files beyond certain size, you should be using createPresigendPost, and specify ContentLength

with getSignedUrl, there is no restricting object size and user can potentially upload a 5TB object (current object limit) to s3


Note that if you can specify ContentLength in params when calling getSignedUrl('putObject',params, callback) you will be thrown

Presigning post data encountered an error { UnexpectedParameter: ContentLength is not supported in pre-signed URLs.

There is an issue on this subject

like image 72
kwalski Avatar answered Sep 21 '22 06:09

kwalski