From b2373d0dde4204fecbf90077b0f8645656cf6058 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Mon, 1 Feb 2021 19:31:25 +0300 Subject: [PATCH] Include request body of multipart/form-data requests into AWS4 signature --- lib/authorizer/aws4.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/authorizer/aws4.js b/lib/authorizer/aws4.js index a7f4f94bb..1fe938106 100644 --- a/lib/authorizer/aws4.js +++ b/lib/authorizer/aws4.js @@ -71,9 +71,16 @@ var _ = require('lodash'), return callback(hash.digest(digestEncoding)); } - // @todo: formdata body type requires adding new data to form instead of setting headers for AWS auth. + // @todo: formdata body type for S3 requires adding new data to form instead of setting headers for AWS auth. // Figure out how to do that. See below link: // AWS auth with formdata: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html + // For now, sign requests as other POST requests for use with API gateway and Lambda functions. + if (body.mode === RequestBody.MODES.formdata) { + formdataBody = bodyBuilder.formdata(body.formdata).body; + hash.update(formdataBody); + + return callback(hash.digest(digestEncoding)); + } // ensure that callback is called if body.mode doesn't match with any of the above modes return callback();