Skip to content

Commit ffd0efb

Browse files
importhumanroidelapluie
authored andcommitted
Deduplicate slashes for sigv4 signature
Signed-off-by: Ujjwal Goyal <[email protected]>
1 parent 902cb39 commit ffd0efb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sigv4/sigv4.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (rt *sigV4RoundTripper) RoundTrip(req *http.Request) (*http.Response, error
115115
}()
116116
req.Body = ioutil.NopCloser(seeker)
117117

118+
// Escape URL like documented in AWS documentation.
119+
// https://docs.aws.amazon.com/sdk-for-go/api/aws/signer/v4/#pkg-overview
120+
req.URL.Path = req.URL.EscapedPath()
121+
118122
// Clone the request and trim out headers that we don't want to sign.
119123
signReq := req.Clone(req.Context())
120124
for _, header := range sigv4HeaderDenylist {

sigv4/sigv4_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,14 @@ func TestSigV4RoundTripper(t *testing.T) {
8989

9090
require.Equal(t, origReq.Header.Get("Authorization"), gotReq.Header.Get("Authorization"))
9191
})
92+
93+
t.Run("Escape URL", func(t *testing.T) {
94+
req, err := http.NewRequest(http.MethodPost, "google.com/test//test", strings.NewReader("Hello, world!"))
95+
require.NoError(t, err)
96+
require.Equal(t, "google.com/test//test", req.URL.Path)
97+
98+
// Escape URL and check
99+
req.URL.Path = req.URL.EscapedPath()
100+
require.Equal(t, "google.com/test/test", req.URL.Path)
101+
})
92102
}

0 commit comments

Comments
 (0)