Skip to content

Commit

Permalink
Encode path components separately
Browse files Browse the repository at this point in the history
Add execute-api to single encoding service list
  • Loading branch information
badslug committed Oct 25, 2020
1 parent 262f917 commit 512efd6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions AWSSignature4DynamicValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ function normalizeLater(path) {
return parts.length < 1 ? '/' : parts.join('/');
}

// encodeComponents will break up a URI path and encode it's components - optionally doing it once
function encodeComponents(path, once) {
console.log('encoding once?', once);
var parts = once ? path.split('/') : normalize(path).split('/');
var encoded = []
parts.forEach(part => {
if (once) {
encoded.push(encodeURIComponent(part))
} else {
encoded.push(encodeURIComponent(encodeURIComponent(part)));
}
})
return encoded.join('/');
}

// See http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
var AWSSignature4DynamicValue = function() {
this.evaluate = function(context) {
Expand Down Expand Up @@ -253,9 +268,7 @@ var AWSSignature4DynamicValue = function() {
// AWS wants the URI normalized (except for s3 which is not normalized) path URL encoded according to RFC 3986.
// Each path segment should be URI-encoded **twice** except for s3 which only gets URI-encoded once.
var target = uri.pathname;
var canonicalURI = service === 's3' ?
encodeURI(target):
encodeURI(encodeURI(normalize(target)));
var canonicalURI = encodeComponents(uri.pathname, service === 's3' || service === 'execute-api');

// Step 1
var canonical = request.method + '\n' +
Expand Down

0 comments on commit 512efd6

Please sign in to comment.