Skip to content

Commit ecbdd11

Browse files
sixemdekobon
authored andcommitted
Add additional encoding when escaping URI path
1 parent 6b21efb commit ecbdd11

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

common/etc/nginx/include/s3gateway.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function s3uri(r) {
358358
}
359359
} else {
360360
if (provide_index_page && _isDirectory(uriPath) ) {
361-
uriPath += INDEX_PAGE;
361+
uriPath += INDEX_PAGE;
362362
}
363363
path = basePath + uriPath;
364364
}
@@ -571,6 +571,7 @@ function _buildSignatureV4(r, amzDatetime, eightDigitDate, creds, bucket, region
571571
} else {
572572
uri = _escapeURIPath(s3uri(r));
573573
}
574+
574575
var canonicalRequest = _buildCanonicalRequest(method, uri, queryParams, host, amzDatetime, creds.sessionToken);
575576

576577
_debug_log(r, 'AWS v4 Auth Canonical Request: [' + canonicalRequest + ']');
@@ -781,6 +782,31 @@ function _padWithLeadingZeros(num, size) {
781782
return s.substr(s.length-size);
782783
}
783784

785+
/**
786+
* Adds additional encoding to a URI component
787+
*
788+
* @param string {string} string to encode
789+
* @returns {string} an encoded string
790+
* @private
791+
*/
792+
function _encodeURIComponent(string) {
793+
var additionalEscapes = [
794+
[/\(/g, '%28'],
795+
[/\)/g, '%29'],
796+
[/\!/g, '%21'],
797+
[/\*/g, '%2A'],
798+
[/\'/g, '%27']
799+
];
800+
801+
var encoded = encodeURIComponent(string);
802+
803+
additionalEscapes.forEach(function (replace) {
804+
encoded = encoded.replace(replace[0], replace[1]);
805+
});
806+
807+
return encoded;
808+
}
809+
784810
/**
785811
* Escapes the path portion of a URI without escaping the path separator
786812
* characters (/).
@@ -795,7 +821,7 @@ function _escapeURIPath(uri) {
795821
let components = [];
796822

797823
decodedUri.split('/').forEach(function (item, i) {
798-
components[i] = encodeURIComponent(item);
824+
components[i] = _encodeURIComponent(item);
799825
});
800826

801827
return components.join('/');
@@ -1038,6 +1064,7 @@ export default {
10381064
// These functions do not need to be exposed, but they are exposed so that
10391065
// unit tests can run against them.
10401066
_padWithLeadingZeros,
1067+
_encodeURIComponent,
10411068
_eightDigitDate,
10421069
_amzDatetime,
10431070
_splitCachedValues,

0 commit comments

Comments
 (0)