Skip to content

Commit

Permalink
fix: Add x-amz-content-sha256 to CanonicalHeaders (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbing0715 committed Oct 16, 2023
1 parent 2134898 commit 085ae0f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion common/etc/nginx/include/awssig4.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const mod_hmac = require('crypto');
* Constant defining the headers being signed.
* @type {string}
*/
const DEFAULT_SIGNED_HEADERS = 'host;x-amz-date';
const DEFAULT_SIGNED_HEADERS = 'host;x-amz-content-sha256;x-amz-date';

/**
* Create HTTP Authorization header for authenticating with an AWS compatible
Expand Down Expand Up @@ -76,6 +76,7 @@ function _buildCanonicalRequest(r,
method, uri, queryParams, host, amzDatetime, sessionToken) {
const payloadHash = awsHeaderPayloadHash(r);
let canonicalHeaders = 'host:' + host + '\n' +
'x-amz-content-sha256:' + payloadHash + '\n' +
'x-amz-date:' + amzDatetime + '\n';

if (sessionToken && sessionToken.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/awssig4_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function _runSignatureV4(r) {
const canonicalRequest = awssig4._buildCanonicalRequest(r,
r.method, req.uri, req.queryParams, req.host, amzDatetime, creds.sessionToken);

var expected = '600721cacc21e3de14416de7517868381831f4709e5c5663bbf2b738e4d5abe4';
var expected = 'cf4dd9e1d28c74e2284f938011efc8230d0c20704f56f67e4a3bfc2212026bec';
var signature = awssig4._buildSignatureV4(r,
amzDatetime, eightDigitDate, creds, region, service, canonicalRequest);

Expand Down

0 comments on commit 085ae0f

Please sign in to comment.