Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit f093ecf

Browse files
author
thisisaaronland
committed
Bug fix: always hash message body even if it's empty
1 parent 30448eb commit f093ecf

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

cmd/aws-sign-request/main.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,20 @@ func main() {
6969

7070
// https://github.com/aws/aws-sdk-go-v2/blob/main/aws/signer/v4/v4.go#L287
7171

72-
body_sha256 := ""
72+
h := sha256.New()
7373

74-
if body_r.Len() > 0 {
74+
_, err = io.Copy(h, body_r)
7575

76-
h := sha256.New()
77-
78-
_, err := io.Copy(h, body_r)
79-
80-
if err != nil {
81-
log.Fatalf("Failed to hash request body, %v", err)
82-
}
76+
if err != nil {
77+
log.Fatalf("Failed to hash request body, %v", err)
78+
}
8379

84-
body_sha256 = fmt.Sprintf("%x", h.Sum(nil))
80+
body_sha256 := fmt.Sprintf("%x", h.Sum(nil))
8581

86-
_, err = body_r.Seek(0, 0)
82+
_, err = body_r.Seek(0, 0)
8783

88-
if err != nil {
89-
log.Fatalf("Failed to rewind message body, %v", err)
90-
}
84+
if err != nil {
85+
log.Fatalf("Failed to rewind message body, %v", err)
9186
}
9287

9388
req, err := http.NewRequest(method, uri, body_r)

0 commit comments

Comments
 (0)