Coder Social home page Coder Social logo

aws-sign-web's People

Contributors

danieljoos avatar dougdomeny avatar jamey-taylor avatar kibrahimcmu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aws-sign-web's Issues

npm hasn't consumed the last hotfix

it seems npm hasn't consumed the last hotfix because the version was not bumped when the hotfix was merged.
Can we change the version from 1.5.0 to 1.5.1 so it can be in npm? thanks!

incorrect signature with empty POST request

When doing a post request with no body, e.g.

axios.post('/someurl')

The generated signature is rejected by AWS (API Gateway in the test I ran). I can workaround the issue by adding an empty object as the second parameter to post.

axios.post('/someurl', {})

Using the `params` field of `AxiosRequestConfig` crashes the new multi-value query param code

In

if (typeof(ws.request.params) === 'object') {
extend(ws.uri.queryParams, ws.request.params);
}

ws.uri.queryParams is parsed from the URI by

function extractQueryParams(search) {
return /^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) {
arg = /^(.+)=(.*)$/.exec(arg);
if (arg) {
var paramKey = decodeURI(arg[1]);
result[paramKey] = (
(typeof result[paramKey] != 'undefined' && result[paramKey] instanceof Array)
? result[paramKey]
: []
).concat(decodeURI(arg[2]));
}
return result;
}, {});
}

into an object whose values are arrays, and so if ws.request.params is empty, then in

flatten(Object.keys(ws.uri.queryParams).sort().map(function (key) {
return ws.uri.queryParams[key].sort().map(function(val) {
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
})

the assumption that ws.uri.queryParams[key] has a sort method is valid.

However, ws.request.params has not undergone any kind of sanitation and can have non-array values, which crashes the above code.

I ran into this problem when attempting to use config.params during a GET request and I have no idea how no one else has run into this! Right now I'm working around this using a custom interceptor in my axios code, which moves config.params into the URI:

client.interceptors.request.use((config) => {
  if (config.params !== undefined) {
    config.url = client.getUri(config);
    config.params = undefined;
  }
  return config;
});

However, I think that to properly address the issue we'd need to either make that signing code handle the non-array case, or sanitize ws.request.params before running extend, by turning its non-array values into arrays.

buildCanonicalRequest fails when using query params

buildCanonicalRequest doesn't appear to work when query params are specified in the request. For example

signer.sign({
  method: 'GET',
  url: '/someurl',
  params: { myId: 'abc' }
});

This line breaks because ws.uri.queryParams[key] is a string and doesn't have sort(). It looks like this assumes the param values are always arrays. That's true if they came from SimpleQueryParser but normal params (merged with extend in prepare) are just strings/numbers.

I tried working around this by adding my own interceptor to wrap all may params in arrays but that doesn't work because Axios then appends [] to the key names.

how to include this lib

Hi,
I am new to browser world so excuse if this sounds naive. I am trying to use this lib on browser side to generate AWS sigV4, stumbled at first block.

I have include the files in html as -

<script src="./crypto-js/index.js"></script>
<script src="./crypto-js/sha256.js"></script>
<script src="./crypto-js/hmac-sha256.js"></script>
<script src="./aws-sign-web/aws-sign-web.js"></script>

This throws multiple errors such as -

sha256.js:19 Uncaught TypeError: Cannot read property 'lib' of undefined
at sha256.js:19
at sha256.js:194
at sha256.js:12
at sha256.js:14

hmac-sha256.js:16 Uncaught TypeError: Cannot read property 'HmacSHA256' of undefined
at hmac-sha256.js:16
at hmac-sha256.js:12
at hmac-sha256.js:14

aws-sign-web.js:19 Uncaught TypeError: Cannot read property 'SHA256' of undefined
at aws-sign-web.js:19
at aws-sign-web.js:21

No clue as to how to solve this. Please help

Use AWS Naming convention for Key and Secret

Nice work Daniel,

I have a suggestion - it would make sense to use the AWS convention for the configuration parameters for the Key and Secret (i.e. accessKeyId and secretAccessKey or use AWSAccessKeyId and AWSSecretAccessKey) as this is what it is in all the AWS documentation.

Then the configuration in the user's Javascript would be:

var config = {
	// AWS Region (default: 'eu-west-1')
	region: 'eu-west-1',
	// AWS service that is called (default: 'execute-api' -- AWS API Gateway)
	service: 'execute-api',
	// AWS IAM credentials, here some temporary credentials with a session token
	accessKeyId: '...',
	secretAccessKey: '...',
	sessionToken: '...'

This would then be consistent with the AWS Response for temporary credentials (http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html

query params in URL are parsed incorrectly

extractQueryParams in SimpleUrlParser uses decodeURI to decode the keys and values. This is incorrect and doesn't work for symbols which are part of the URL grammar. It should be using decodeURIComponent.

Example:
testParam: 'Cookies & Cream'
->

sample-url?testParam=Cookies%26Cream

->
Decoded queryParams:

{
   testParam: 'Cookies%26Cream'
}

This is causing an invalid signature to be generated.

URLs with percent (%) encoded values fails signature check

URLs with percent (%) encoded values get decoded and fail to match signature.

This snippet in SimpleUriParser decodes the path but doesn't encode it initially. This results in any URL-encoded characters to be un-encoded. For example, %20 is changed to a space.

return function (uri) {
parser.href = uri;
return {
      protocol: parser.protocol,
      host: parser.host.replace(/^(.*):((80)|(443))$/, '$1'),
      path: ((parser.pathname.charAt(0) !== '/') ? '/' : '') +
              decodeURIComponent(parser.pathname),
      queryParams: extractQueryParams(parser.search)
      };
};

A solution is to encode the uri parameter, as shown below.

return function (uri) {
parser.href = **encodeURI**(uri);
return {
     protocol: parser.protocol,
     host: parser.host.replace(/^(.*):((80)|(443))$/, '$1'),
     path: ((parser.pathname.charAt(0) !== '/') ? '/' : '') +
          decodeURIComponent(parser.pathname),
     queryParams: extractQueryParams(parser.search)
      };
};

aws signature v4 - new headers

Hi Daniel,
thank for lib, it's awesome ! :)
I try to use it in a personnal project but I have problems about authorization.
Now, aws s3 signature v4 impose new header (X-Amz-Content-Sha256) and signedheaders (x-amz-content-sha256;x-amz-date;x-amz-security-token).
So I include it in your code but it doesn't work. Amazon server reply that my signature doesn't match (isn't good).
Are you still using your library ? does it work ?
Can I send you my code (your lib with my changes) to have your opinion ?
Thank you :)

issue with defining HmacSHA256

  • Hello there. I'm trying out your library and I ran into this error on the console,

image

  • The context appears to be ...
// excerpt from aws-sign-web.js
            hmac: function (key, input, options) {
                options = extend({hexOutput: true, textInput: true}, options);
                var hmac = CryptoJS.HmacSHA256(input, key, {asBytes: true});    // Line 286
                if (options.hexOutput) {
                    return hmac.toString(CryptoJS.enc.Hex);
                }
                return hmac;
            }
  • Potential culprit: I am leaving out the sessionToken. I am not sure if you require that? I have used Signature Version 4 with a Python implementation which did not require this.
  • Also, I forgot to mention, I changed my vanilla.html setup to also include core.js, because errors were complaining about CryptoJS undefined in sha256.js
	<script src="js/core.js"></script>
	<script src="js/sha256.js"></script>
	<script src="js/hmac-sha256.js"></script>
	<script src="js/aws-sign-web.js"></script>

Please let me know if I can provide more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.