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

PUT works inconsistent. #278

Open
delgermurun opened this issue Apr 9, 2015 · 1 comment
Open

PUT works inconsistent. #278

delgermurun opened this issue Apr 9, 2015 · 1 comment

Comments

@delgermurun
Copy link

I created bucket in US Standart region. I'm uploading file via stream.

So sometimes it works, sometimes not. I tried to set region to us-west-2 and 'us-east-1`, but still same. Works inconsistent.

Error message is:

<Error><Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJOX5SZFWUSX6AHRA</AWSAccessKeyId><StringToSign>

status code is 403

@lbeschastny
Copy link

I encountered the same issue just now and found what was causing it in my project.

When knox generates signed AWS uri it relies on require('querystring').stringify here, but some third-party modules may monkey-patch it. For example, googlemapsutil overwrites require('querystring').escape method with identity function. Because of it, require('querystring').stringify leaves all '+' characters unencoded instead of encoding them with '%2B' string.

But when AWS receives your request, it decodes all '+' characters to white spaces (which is also an incorrect behavior in my opinion).

So, if generated signature contain any number of '+' characters then you'll receive AWS API error, telling you that SignatureDoesNotMatch. If you'll look closely at returned XML you'll see that SignatureProvided field contains your signature with all '+' characters replaced by white spaces.

You could fix it by restoring require('querystring').escape function:

require('querystring').escape = function (str) {
  return encodeURIComponent(str);
}

or by replacing all '+' characters in a generated uri with '%2B' string yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants