aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

SignatureDoesNotMatch error when S3 key contains *

Open TsvetanMilanov opened this issue 3 years ago • 5 comments

Describe the bug When trying to get/put object with key which contains * (e.g. te*st) the S3 client throws SignatureDoesNotMatch error.

SDK version number 3.2.0

Is the issue in the browser/Node.js/ReactNative? Node.js

Details of the browser/Node.js/ReactNative version v12.16.1

To Reproduce (observed behavior)

const { S3 } = require("@aws-sdk/client-s3");

const s3 = new S3({ region: "us-east-1" });
await s3.putObject({ Bucket: "test-signature-sdk-v3", Key: "test*", Body: "test" });

Expected behavior Expecting the method invocation to succeed, but it throws SignatureDoesNotMatch error.

Additional context There is a similar issue https://github.com/aws/aws-sdk-js-v3/issues/283 and a related fix https://github.com/aws/aws-sdk-js-v3/pull/284. The S3 client works with : (e.g. te:st) but not with *. The aws-sdk v2 works correctly with key te*st

TsvetanMilanov avatar Jan 11 '21 15:01 TsvetanMilanov

Hey @TsvetanMilanov I was able to reproduce this issue, it is currently in our high priority list, the issue will be updated once it has been fixed.

ajredniwja avatar Mar 03 '21 03:03 ajredniwja

This happens because encodeURIComponent doesn't escape *.

Currently the additional encoding is only done in signer, and some additional characters will be required to be escaped https://github.com/aws/aws-sdk-js-v3/blob/906e4b04d18ba26cbe16d9122b0014ea539233ac/packages/signature-v4/src/SignatureV4.ts#L280-L283

The solution would be to do additional encoding on top of encodeURIComponent output. Code from v2: https://github.com/aws/aws-sdk-js/blob/dd83d672170e8cc0c52a20df29a43e7663e5336a/lib/util.js#L41-L46

trivikr avatar Mar 18 '21 20:03 trivikr

Bump, can the suggest change be implemented?

dobrynin avatar Mar 15 '22 22:03 dobrynin

This error is being exist. "@aws-sdk/client-s3": "^3.142.0",

live680g avatar Aug 09 '22 09:08 live680g

myString.replace("*", "%2A"); fixed for me.

dobrynin avatar Aug 09 '22 17:08 dobrynin

This also happens when metadata contains special/unicode characters, such as ContentDisposition, which I've been wrestling with lately.

Using the latest SDK and specifically the CopyObjectCommand, as I'm trying to update metadata for a lot of files, as part of a migration to S3, however this has been a rather unpleasant surprise.

Dids avatar Apr 26 '23 15:04 Dids

Hi @TsvetanMilanov, @Dids, @dobrynin, @live680g, this issue has been fixed. Please update to the latest version of the SDK you should have not issues.

If you folks have anything else that we can help with, please feel free of opening a new issue.

Thanks!

yenfryherrerafeliz avatar Oct 26 '23 18:10 yenfryherrerafeliz

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[bot] avatar Nov 10 '23 00:11 github-actions[bot]