Compare commits

...

1 Commits

Author SHA1 Message Date
Rahul Padigela 70e5624729 improvement: ARSN-36 handle duplicate query params
Handle duplicate references of query params by flattening the array
and picking the first occurence of the duplicate param
2021-11-01 18:19:05 -07:00
2 changed files with 27 additions and 0 deletions

View File

@ -839,6 +839,21 @@ const routesUtils = {
request.objectKey = resources.object; request.objectKey = resources.object;
request.parsedHost = resources.host; request.parsedHost = resources.host;
request.path = resources.path; request.path = resources.path;
/**
* Flatten duplicate query params
* Duplicate query params in url e.g. ?a=1&a=2&a=3&b=4&c=5 are parsed
* by the HTTP parser as { a: [1, 2, 3], b: 4, c: 5}. Since duplicate
* params are invalid in AWS S3 it's reduced to the value of the first
* occurence of the duplicate query param
* */
const queryParams = request.query;
Object.keys(queryParams).forEach(key => {
const param = queryParams[key];
if (Array.isArray(param)) {
queryParams[key] = param.reduce(prev => prev);
}
});
// For streaming v4 auth, the total body content length // For streaming v4 auth, the total body content length
// without the chunk metadata is sent as // without the chunk metadata is sent as
// the x-amz-decoded-content-length // the x-amz-decoded-content-length

View File

@ -76,4 +76,16 @@ describe('routesUtils.normalizeRequest', () => {
assert.strictEqual(result.objectKey, objName); assert.strictEqual(result.objectKey, objName);
assert.strictEqual(result.parsedHost, 's3.amazonaws.com'); assert.strictEqual(result.parsedHost, 's3.amazonaws.com');
}); });
it('should pick the first occurence of the query param when duplicates ' +
'are present ', () => {
const request = {
url: `/${bucketName}/${objName}?a=1&a=2&a=3&b=4&c=5`,
headers: { host: 's3.amazonaws.com' },
};
const result = routesUtils.normalizeRequest(request, validHosts);
assert.strictEqual(result.query.a, '1');
assert.strictEqual(result.query.b, '4');
assert.strictEqual(result.query.c, '5');
});
}); });