diff options
author | isaacs <i@izs.me> | 2020-07-23 20:58:04 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:53:42 +0300 |
commit | ad5e07d8bd86d1dbe2b03dc142f8c8d6f4828ffe (patch) | |
tree | 97b66f97d77f35774f10a5e3e9957b1897d150bb /node_modules/aws4/aws4.js | |
parent | a16994cfdd2f255016f3d8ee60d03473d80eabd8 (diff) |
Full dependency reboot
Reinstall everything from a clean node_modules and package-lock.json
state.
Re-generate list of bundleDependencies and node_modules/.gitignore with
a script that does the right thing based on actual dependency state.
Diffstat (limited to 'node_modules/aws4/aws4.js')
-rw-r--r-- | node_modules/aws4/aws4.js | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/node_modules/aws4/aws4.js b/node_modules/aws4/aws4.js index 124cd7ac4..ed282f85b 100644 --- a/node_modules/aws4/aws4.js +++ b/node_modules/aws4/aws4.js @@ -22,6 +22,10 @@ function encodeRfc3986(urlEncodedString) { }) } +function encodeRfc3986Full(str) { + return encodeRfc3986(encodeURIComponent(str)) +} + // request: { path | body, [host], [method], [headers], [service], [region] } // credentials: { accessKeyId, secretAccessKey, [sessionToken] } function RequestSigner(request, credentials) { @@ -29,7 +33,7 @@ function RequestSigner(request, credentials) { if (typeof request === 'string') request = url.parse(request) var headers = request.headers = (request.headers || {}), - hostParts = this.matchHost(request.hostname || request.host || headers.Host || headers.host) + hostParts = (!this.service || !this.region) && this.matchHost(request.hostname || request.host || headers.Host || headers.host) this.request = request this.credentials = credentials || this.defaultCredentials() @@ -66,6 +70,19 @@ RequestSigner.prototype.matchHost = function(host) { if (hostParts[1] === 'es') hostParts = hostParts.reverse() + if (hostParts[1] == 's3') { + hostParts[0] = 's3' + hostParts[1] = 'us-east-1' + } else { + for (var i = 0; i < 2; i++) { + if (/^s3-/.test(hostParts[i])) { + hostParts[1] = hostParts[i].slice(3) + hostParts[0] = 's3' + break + } + } + } + return hostParts } @@ -79,10 +96,9 @@ RequestSigner.prototype.isSingleRegion = function() { } RequestSigner.prototype.createHost = function() { - var region = this.isSingleRegion() ? '' : - (this.service === 's3' && this.region !== 'us-east-1' ? '-' : '.') + this.region, - service = this.service === 'ses' ? 'email' : this.service - return service + region + '.amazonaws.com' + var region = this.isSingleRegion() ? '' : '.' + this.region, + subdomain = this.service === 'ses' ? 'email' : this.service + return subdomain + region + '.amazonaws.com' } RequestSigner.prototype.prepareRequest = function() { @@ -220,12 +236,22 @@ RequestSigner.prototype.canonicalString = function() { } if (query) { - queryStr = encodeRfc3986(querystring.stringify(Object.keys(query).sort().reduce(function(obj, key) { + var reducedQuery = Object.keys(query).reduce(function(obj, key) { if (!key) return obj - obj[key] = !Array.isArray(query[key]) ? query[key] : - (firstValOnly ? query[key][0] : query[key].slice().sort()) + obj[encodeRfc3986Full(key)] = !Array.isArray(query[key]) ? query[key] : + (firstValOnly ? query[key][0] : query[key]) return obj - }, {}))) + }, {}) + var encodedQueryPieces = [] + Object.keys(reducedQuery).sort().forEach(function(key) { + if (!Array.isArray(reducedQuery[key])) { + encodedQueryPieces.push(key + '=' + encodeRfc3986Full(reducedQuery[key])) + } else { + reducedQuery[key].map(encodeRfc3986Full).sort() + .forEach(function(val) { encodedQueryPieces.push(key + '=' + val) }) + } + }) + queryStr = encodedQueryPieces.join('&') } if (pathStr !== '/') { if (normalizePath) pathStr = pathStr.replace(/\/{2,}/g, '/') @@ -233,8 +259,8 @@ RequestSigner.prototype.canonicalString = function() { if (normalizePath && piece === '..') { path.pop() } else if (!normalizePath || piece !== '.') { - if (decodePath) piece = decodeURIComponent(piece) - path.push(encodeRfc3986(encodeURIComponent(piece))) + if (decodePath) piece = decodeURIComponent(piece).replace(/\+/g, ' ') + path.push(encodeRfc3986Full(piece)) } return path }, []).join('/') @@ -289,8 +315,16 @@ RequestSigner.prototype.defaultCredentials = function() { } RequestSigner.prototype.parsePath = function() { - var path = this.request.path || '/', - queryIx = path.indexOf('?'), + var path = this.request.path || '/' + + // S3 doesn't always encode characters > 127 correctly and + // all services don't encode characters > 255 correctly + // So if there are non-reserved chars (and it's not already all % encoded), just encode them all + if (/[^0-9A-Za-z;,/?:@&=+$\-_.!~*'()#%]/.test(path)) { + path = encodeURI(decodeURI(path)) + } + + var queryIx = path.indexOf('?'), query = null if (queryIx >= 0) { @@ -298,15 +332,6 @@ RequestSigner.prototype.parsePath = function() { path = path.slice(0, queryIx) } - // S3 doesn't always encode characters > 127 correctly and - // all services don't encode characters > 255 correctly - // So if there are non-reserved chars (and it's not already all % encoded), just encode them all - if (/[^0-9A-Za-z!'()*\-._~%/]/.test(path)) { - path = path.split('/').map(function(piece) { - return encodeURIComponent(decodeURIComponent(piece)) - }).join('/') - } - this.parsedPath = { path: path, query: query, |