Skip to content

Commit

Permalink
fix(storage): encode + in SignedURL query params (#2895)
Browse files Browse the repository at this point in the history
This must be encoded for the signature to be correct if a
query parameter contains a plus sign. We have a conformance
test case for this which can now be unskipped.

Fixes #2876
  • Loading branch information
tritone committed Sep 22, 2020
1 parent e178552 commit 748efd5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 0 additions & 3 deletions storage/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ func TestSigningV4Conformance(t *testing.T) {
for _, testFile := range testFiles {
for _, tc := range testFile.SigningV4Tests {
t.Run(tc.Description, func(t *testing.T) {
if tc.Description == "Query Parameter Encoding" {
t.Skip("https://github.com/googleapis/google-cloud-go/issues/2876")
}
utcNow = func() time.Time {
return time.Unix(tc.Timestamp.Seconds, 0).UTC()
}
Expand Down
6 changes: 4 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ func signedURLV4(bucket, name string, opts *SignedURLOptions, now time.Time) (st
for k, v := range opts.QueryParameters {
canonicalQueryString[k] = append(canonicalQueryString[k], v...)
}

fmt.Fprintf(buf, "%s\n", canonicalQueryString.Encode())
// url.Values.Encode escaping is correct, except that a space must be replaced
// by `%20` rather than `+`.
escapedQuery := strings.Replace(canonicalQueryString.Encode(), "+", "%20", -1)
fmt.Fprintf(buf, "%s\n", escapedQuery)

// Fill in the hostname based on the desired URL style.
u.Host = opts.Style.host(bucket)
Expand Down

0 comments on commit 748efd5

Please sign in to comment.