Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-signed GetObject requests with Range header throws SignatureDoesNotMatch exception #4823

Closed
josiahmann opened this issue Jun 12, 2023 · 3 comments
Assignees
Labels
response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@josiahmann
Copy link

Describe the bug

We've uploaded some large files to AWS and are trying to build a "preview" feature which will only show the first 1MB of the already uploaded file.

The AWS documentation suggests the Range header, but when that param is added a SignatureDoesNotMatch error is thrown.

Expected Behavior

I expected to get back the first 1Mb of the uploaded file.

Current Behavior

SignatureDoesNotMatch error is thrown.

Reproduction Steps

const client = new S3({region}); const command = new GetObjectCommand({ Bucket: bucket, Key: key, Range: "bytes=0-10000", }); const url = await getSignedUrl(client, command, { expiresIn: 3600 });

Code works as expected without the Range param.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

3.209

Environment details (OS name and version, etc.)

Mac OS Ventura 13.4

@josiahmann josiahmann added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 12, 2023
@yenfryherrerafeliz
Copy link
Contributor

yenfryherrerafeliz commented Jun 12, 2023

Hi @josiahmann, thanks for opening this issue. The reason why you are getting this error is because the Range header is being signed but not provided when executing the request. At this time, the only option you have here is to provide the range header when actually executing the request. For example:

import {GetObjectCommand, S3Client} from "@aws-sdk/client-s3";
import {getSignedUrl} from "@aws-sdk/s3-request-presigner";

const client = new S3Client({
    region: 'us-east-2'
});
const url = await getSignedUrl(client, new GetObjectCommand({
    Bucket: process.env.TEST_REGION,
    Key: process.env.TEST_KEY,
    Range: "0-19"
}));
const response = await fetch(url, {
    method: 'GET',
    headers: {
        "range": "0-19"
    }
});

console.log(response.status)
console.log(await response.text())

Note: the range parameter works fine when doing a GetObject request without using presigned urls, because the header is injected at execution time, but when working with s3 presigned urls, the header values sometimes are include in the query string parameters, but in this case the parameter range as header is not supported by the s3 service.

I hope this helps!

Thanks!

@yenfryherrerafeliz yenfryherrerafeliz added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 12, 2023
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Jun 12, 2023
@yenfryherrerafeliz yenfryherrerafeliz transferred this issue from aws/aws-sdk-js Jun 12, 2023
@josiahmann
Copy link
Author

Thank you! That is super helpful!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants