From 148b9f75a5b4bd41c8204119768a96dae3bd0f5c Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Wed, 30 Aug 2017 12:26:10 -0700 Subject: [PATCH] Revert "aws/signer/v4: Fix Signing Unordered Multi Value Query Parameters (#1491)" This reverts commit 39a358f9d642fe3804762f998b8cfbe46ba5a61a. --- aws/signer/v4/v4.go | 4 ++++ aws/signer/v4/v4_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/aws/signer/v4/v4.go b/aws/signer/v4/v4.go index cdfa22d5aad..15da57249a1 100644 --- a/aws/signer/v4/v4.go +++ b/aws/signer/v4/v4.go @@ -324,6 +324,10 @@ func (v4 Signer) signWithBody(r *http.Request, body io.ReadSeeker, service, regi unsignedPayload: v4.UnsignedPayload, } + for key := range ctx.Query { + sort.Strings(ctx.Query[key]) + } + if ctx.isRequestSigned() { ctx.Time = currentTimeFn() ctx.handlePresignRemoval() diff --git a/aws/signer/v4/v4_test.go b/aws/signer/v4/v4_test.go index 178ad816596..45d0eb8869a 100644 --- a/aws/signer/v4/v4_test.go +++ b/aws/signer/v4/v4_test.go @@ -128,14 +128,14 @@ func TestPresignRequest(t *testing.T) { func TestPresignBodyWithArrayRequest(t *testing.T) { req, body := buildRequest("dynamodb", "us-east-1", "{}") - req.URL.RawQuery = "FooB=a&FooA=b&FooA=a&FooB=b" + req.URL.RawQuery = "Foo=z&Foo=o&Foo=m&Foo=a" signer := buildSigner() signer.Presign(req, body, "dynamodb", "us-east-1", 300*time.Second, time.Unix(0, 0)) expectedDate := "19700101T000000Z" expectedHeaders := "content-length;content-type;host;x-amz-meta-other-header;x-amz-meta-other-header_with_underscore" - expectedSig := "60152079d308a87f036082a236c935261221a32d369ec4b6b75dbc9873d2ab9a" + expectedSig := "fef6002062400bbf526d70f1a6456abc0fb2e213fe1416012737eebd42a62924" expectedCred := "AKID/19700101/us-east-1/dynamodb/aws4_request" expectedTarget := "prefix.Operation" @@ -519,7 +519,7 @@ func TestSignWithRequestBody_Overwrite(t *testing.T) { func TestBuildCanonicalRequest(t *testing.T) { req, body := buildRequest("dynamodb", "us-east-1", "{}") - req.URL.RawQuery = "FooB=a&FooA=b&FooA=a&FooB=b" + req.URL.RawQuery = "Foo=z&Foo=o&Foo=m&Foo=a" ctx := &signingCtx{ ServiceName: "dynamodb", Region: "us-east-1", @@ -531,7 +531,7 @@ func TestBuildCanonicalRequest(t *testing.T) { } ctx.buildCanonicalString() - expected := "https://example.org/bucket/key-._~,!@#$%^&*()?FooA=b&FooA=a&FooB=a&FooB=b" + expected := "https://example.org/bucket/key-._~,!@#$%^&*()?Foo=z&Foo=o&Foo=m&Foo=a" if e, a := expected, ctx.Request.URL.String(); e != a { t.Errorf("expect %v, got %v", e, a) }