Skip to content

Commit 88371e0

Browse files
committed
fix: unsigned payload being treated as string
1 parent 75d7282 commit 88371e0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/core/__tests__/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { getHashedPayload } from '../../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload';
5+
import { UNSIGNED_PAYLOAD } from '../../../../../../../src/clients/middleware/signing/signer/signatureV4/constants';
56

67
describe('getHashedPayload', () => {
78
test('returns empty hash if nullish', () => {
@@ -34,4 +35,13 @@ describe('getHashedPayload', () => {
3435
expect(getHashedPayload(scalar as any)).toStrictEqual('UNSIGNED-PAYLOAD');
3536
}
3637
});
38+
39+
test('returns UNSIGNED_PAYLOAD constant without hashing when passed as body', () => {
40+
expect(getHashedPayload(UNSIGNED_PAYLOAD as any)).toStrictEqual(
41+
'UNSIGNED-PAYLOAD',
42+
);
43+
expect(getHashedPayload(UNSIGNED_PAYLOAD as any)).not.toStrictEqual(
44+
'438d4109ef0d676b8c2c7ed13cdfcb418e494d53b843d4634ce3b1085f07bb96',
45+
);
46+
});
3747
});

packages/core/src/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const getHashedPayload = (body: HttpRequest['body']): string => {
3434
};
3535

3636
const isSourceData = (body: HttpRequest['body']): body is SourceData =>
37-
typeof body === 'string' || ArrayBuffer.isView(body) || isArrayBuffer(body);
37+
// Exclude UNSIGNED_PAYLOAD constant to prevent it from being hashed as a string
38+
body !== UNSIGNED_PAYLOAD &&
39+
(typeof body === 'string' || ArrayBuffer.isView(body) || isArrayBuffer(body));
3840

3941
const isArrayBuffer = (arg: any): arg is ArrayBuffer =>
4042
(typeof ArrayBuffer === 'function' && arg instanceof ArrayBuffer) ||

0 commit comments

Comments
 (0)