Skip to content

Commit e216071

Browse files
authored
aws/signer/v4: Keep Object-Lock headers a header in presigning signing requests (#1307)
Updates the Sigv4 request signer to use keep X-Amz-Object-Lock-* headers as headers, and not hoisted to the query string for presigned URLs. Revision of #1215
1 parent 77ed784 commit e216071

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "4b776031-a695-41ca-a111-950fd7dbe4fa",
3+
"type": "bugfix",
4+
"description": "Keep Object-Lock headers a header when presigning Sigv4 signing requests",
5+
"modules": [
6+
"."
7+
]
8+
}

aws/signer/internal/v4/header_rules.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ func (m MapRule) IsValid(value string) bool {
3434
return ok
3535
}
3636

37-
// Whitelist is a generic Rule for whitelisting
38-
type Whitelist struct {
37+
// AllowList is a generic Rule for include listing
38+
type AllowList struct {
3939
Rule
4040
}
4141

42-
// IsValid for Whitelist checks if the value is within the Whitelist
43-
func (w Whitelist) IsValid(value string) bool {
42+
// IsValid for AllowList checks if the value is within the AllowList
43+
func (w AllowList) IsValid(value string) bool {
4444
return w.Rule.IsValid(value)
4545
}
4646

47-
// Blacklist is a generic Rule for blacklisting
48-
type Blacklist struct {
47+
// ExcludeList is a generic Rule for exclude listing
48+
type ExcludeList struct {
4949
Rule
5050
}
5151

52-
// IsValid for Whitelist checks if the value is within the Whitelist
53-
func (b Blacklist) IsValid(value string) bool {
52+
// IsValid for AllowList checks if the value is within the AllowList
53+
func (b ExcludeList) IsValid(value string) bool {
5454
return !b.Rule.IsValid(value)
5555
}
5656

aws/signer/internal/v4/headers.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package v4
22

33
// IgnoredHeaders is a list of headers that are ignored during signing
44
var IgnoredHeaders = Rules{
5-
Blacklist{
5+
ExcludeList{
66
MapRule{
77
"Authorization": struct{}{},
88
"User-Agent": struct{}{},
@@ -11,9 +11,9 @@ var IgnoredHeaders = Rules{
1111
},
1212
}
1313

14-
// RequiredSignedHeaders is a whitelist for Build canonical headers.
14+
// RequiredSignedHeaders is a allow list for Build canonical headers.
1515
var RequiredSignedHeaders = Rules{
16-
Whitelist{
16+
AllowList{
1717
MapRule{
1818
"Cache-Control": struct{}{},
1919
"Content-Disposition": struct{}{},
@@ -56,12 +56,13 @@ var RequiredSignedHeaders = Rules{
5656
"X-Amz-Tagging": struct{}{},
5757
},
5858
},
59+
Patterns{"X-Amz-Object-Lock-"},
5960
Patterns{"X-Amz-Meta-"},
6061
}
6162

62-
// AllowedQueryHoisting is a whitelist for Build query headers. The boolean value
63+
// AllowedQueryHoisting is a allowed list for Build query headers. The boolean value
6364
// represents whether or not it is a pattern.
6465
var AllowedQueryHoisting = InclusiveRules{
65-
Blacklist{RequiredSignedHeaders},
66+
ExcludeList{RequiredSignedHeaders},
6667
Patterns{"X-Amz-"},
6768
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package v4
2+
3+
import "testing"
4+
5+
func TestAllowedQueryHoisting(t *testing.T) {
6+
cases := map[string]struct {
7+
Header string
8+
ExpectHoist bool
9+
}{
10+
"object-lock": {
11+
Header: "X-Amz-Object-Lock-Mode",
12+
ExpectHoist: false,
13+
},
14+
"s3 metadata": {
15+
Header: "X-Amz-Meta-SomeName",
16+
ExpectHoist: false,
17+
},
18+
"another header": {
19+
Header: "X-Amz-SomeOtherHeader",
20+
ExpectHoist: true,
21+
},
22+
"non X-AMZ header": {
23+
Header: "X-SomeOtherHeader",
24+
ExpectHoist: false,
25+
},
26+
}
27+
28+
for name, c := range cases {
29+
t.Run(name, func(t *testing.T) {
30+
if e, a := c.ExpectHoist, AllowedQueryHoisting.IsValid(c.Header); e != a {
31+
t.Errorf("expect hoist %v, was %v", e, a)
32+
}
33+
})
34+
}
35+
}

0 commit comments

Comments
 (0)