Using Range with presigned url AWS S3 - amazon-web-services

When I create a presigned url - it generates a X-Amz-Signature.
Using this signature in the query param along with the Range query param causes the signatur to then be invalid. Is there anyway to get around this?
The request signature we calculated does not match the signature you provided. Check your key and signing method.

The signature will no longer be valid if you change the URL's query parameters or headers after creating it, which will lead to the error
The request signature we calculated does not match the signature you provided. Check your key and signing method.
Your question doesn't make clear which query parameter you are updating, however, it's possible that you are doing so after creating the pre-signed URL if you are changing the "Range" query parameter. If this is the case, the changed Range header would render the signature invalid because it is used in the calculation of the signature.
Solution : Create a fresh pre-signed URL with the amended Range header to get around this. If the Range header needs to be changed frequently, write a function that produces a fresh pre-signed URL each time the Range header is changed.

Related

API Gateway REST API integration request path rewriting with multiple path parts

I have an API Gateway REST API with an integration to S3. We don't want to directly expose the buckets and object keys so there is an authorizer that is taking a path parameter and returning an object key. This object key may contain a number of path parameters, eg, path/to/object. I want to be able to rewrite the integration path to include this.
When I try using a path variable the value is replaced but it's URL encoded, ie, path%2Fto%2Fobject so of course the S3 request fails. I don't see any way of replacing the path variable with a value that contains multiple path parameters. I've also tried the same thing using #context.requestOverride.path.XXX in a mapping template and it also ends up URL encoded. I've tried using $utils.urlDecode() but again the result is encoded.
Is there any way to replace a path variable with multiple path segments? Otherwise, is there a way to completely replace the path in a mapping template (not just specific path variables)? Or is there another way to achieve this eg can the object key be passed in a header?

REST API GetBucketCors with AWS4

I am trying to perform GetBucketCors operation using REST API and new AWS4 authorization. It works perfectly when I use old auth method but I cannot find out how to set canonical request right in AWS4.
I am trying to add 'cors' as first query parameter and include it into canonical request but in most of times I get error: "The request signature we calculated does not match the signature you provided. Check your key and signing method."
Can you suggest what should right query string should be? This is noh my canonical request looks like:
GET
/
cors&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJSZ2LLOUSEHIJVQQ%2F20210316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210316T192947Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host
host:<BUCKET_NAME>.s3.amazonaws.com
host
UNSIGNED-PAYLOAD
OK, I have finally found it out (hint: look at amazon response more ;)
"cors" should be additional query param with "="
GET
/<BUCKET_NAME>/
X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJSZ2LLOUSEHIJVQQ%2F20210317%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210317T210203Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&cors=
host:s3.amazonaws.com
host
UNSIGNED-PAYLOAD

Postman path parameter following = in the request url

One of the requests for the tool I've been asked to update is the delete request which is structured as follows:
http://{{host_ip}}:{{port}}/lists/list_id=76218cb5fc45605cd632c26f5c5568ac/del
where the list ID will be different every time you send a request.
In order to simplify usage for end users, I want to be able to have them enter everything they need as parameters or headers in the postman GUI as they do for the other requests, rather than modifying the request URL, so I tried something like this:
http://{{host_ip}}:{{port}}/lists/list_id=:list_id/del
but if the : is preceded by an equals sign, the postman parameters tab no longer shows list_id as a path parameter.
Is there a way to make this work using a path parameter? Or is the best solution to explain to users that for the delete request, they need to paste the list_id obtained from the other requests into the request URL?
http://{{host_ip}}:{{port}}/lists/list_id={{list_id}}/del?list_id=1
Now users can pass the list id as query parameter.
In pre-request:
pm.environment.set("list_id",pm.request.url.getQueryString("list_id").split("=")[1])
pm.request.removeQueryParams("list_id")
this will update the list_id varaible and remove the query parameter and send the request in the format you want
If you want to achieve what you are saying then there is no solution for your problem.
But I would suggest you change your URL. As Divyang said, your URL should be like http://{{host_ip}}:{{port}}/lists/{{list_id}}/del or http://{{host_ip}}:{{port}}/lists/del?list_id=123 and then you can use params tab assign values to list_id.
But my best suggestion would be to use RESTful design: http://{{host_ip}}:{{port}}/lists/123123 and make a DELETE request to that URL.

How to make a request in Postman

Arabam is an e-commerce site that I am attempting to query. As an example, given the automobile page, you can add query parameters to the page such as days and sort as follows:
https://www.arabam.com/ikinci-el/otomobil?days=30&sort=startedAt.desc
I will be accessing the data via their API, however, which lives at:
https://api.arabam.com/listing/v2/search
And here is the API Key I'm using:
_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA==
I am able to make the request using Postman:
But whichever query parameters I pass, the total number of keys in the response remains the same. How do I pass parameters correctly? Either I am not passing them correctly, or these are not the correct parameters. How do I find correct parameters?
I'm relatively new to this so need a bit of guidance.
Have you tried posting the params as a json body instead

How to add a query string parameter to Cloudfront?

I would like to add a query string parameter to my Cloudfront Url to be able to get some additional info into the Cloudfront log. I have two distributions, one is signed and one is not signed, pointing to two different S3 buckets (one with audio, one with images).
Access to both distributions works fine without added query strings, but if I add a query parameter like the test one below:
https://x.cloudfront.net/audio.m4a?li=...62&Expires=1544430879&Signature=...QTQ__&Key-Pair-Id=xxx&test=fail
https://y.cloudfront.net/image.jpg?test=allgood
The first one fails (Access Denied) but the second one works fine.
Neither one of the distributions forwards the query string to S3.
The signed audio distribution has logging enabled while the image distribution doesn't have logging. Besides this, their setups are the same.
What do I need to do in order to get the audio distribution to accept my custom query parameter?
Thanks
/o
One of the core concepts behind signed URLs is that they are not vulnerable to tampering -- you can't change a signed URL and have it remain valid.
CloudFront uses the public key to validate the signature and confirm that the URL hasn't been tampered with. If the signature is invalid, the request is rejected.
...
Signed CloudFront URLs cannot contain extra query string arguments. If you add a query string to a signed URL after you create it, the URL returns an HTTP 403 status.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls.html
To add a query string parameter to a CloudFront signed URL, you need to add it before signing the URL... because the addition will change the signature.
Additional/Optional parameters can be allowed for a signed cloudfront URL by appending an asterisk (*) to the resource in the signature policy.
For example, if you sign the URL: https://example.com/images/funny/cat.png* then you will be able to add optional parameters to the URL.
If the parameters should not be optional you could also sign it like this: https://example.com/images/funny/cat.png?w=*&h=*. This way the values of the w and h params may be anything but both parameters must be set.