Unverified Commit 53b35afd authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

fix(signing): Fix duplicate content-length header (#697)

If `content_length` was set explicitly, we were erroneously duplicating it for non-streaming bodies. This commit:
- Uses `set_header_if_absent` to avoid double setting content length
- Adds a trace level log of the canonical request during signing
- Adds an additional protocol test that fails prior to this change
parent cd58b0f9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
vNext (Month Day, Year)
=======================

**New This Week**
- :bug: Fixes issue where `Content-Length` header could be duplicated leading to signing failure (aws-sdk-rust#220, smithy-rs#697)

v0.22 (September 2nd, 2021)
===========================

+3 −0
Original line number Diff line number Diff line
vNext (Month Day, Year)
=======================

**New This Week**
- :bug: Fixes issue where `Content-Length` header could be duplicated leading to signing failure (aws-sdk-rust#220, smithy-rs#697)

v0.0.17-alpha (September 2nd, 2021)
===================================

+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ http-body = { version = "0.4", optional = true }
percent-encoding = { version = "2.1", optional = true }
ring = "0.16"
smithy-eventstream = { path = "../../../rust-runtime/smithy-eventstream", optional = true }
tracing = "0.1"

[dev-dependencies]
bytes = "1"
+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ pub fn calculate_signing_headers<'a, B>(
    } = params;
    let (creq, extra_headers) =
        CanonicalRequest::from(request, body, settings, *date_time, *security_token)?;
    tracing::trace!(canonical_request = %creq);

    // Step 2: https://docs.aws.amazon.com/en_pv/general/latest/gr/sigv4-create-string-to-sign.html.
    let encoded_creq = &sha256_hex_string(creq.to_string().as_bytes());
+15 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ apply CreateMultipartUpload @httpRequestTests([

apply PutObject @httpRequestTests([
    {
        id: "DontSendMultipleContentTypeHeaders",
        id: "DontSendDuplicateContentType",
        documentation: "This test validates that if a content-type is specified, that only one content-type header is sent",
        method: "PUT",
        protocol: "aws.protocols#restXml",
@@ -167,5 +167,19 @@ apply PutObject @httpRequestTests([
            Key: "test-key",
            ContentType: "text/html"
        }
    },
    {
        id: "DontSendDuplicateContentLength",
        documentation: "This test validates that if a content-length is specified, that only one content-length header is sent",
        method: "PUT",
        protocol: "aws.protocols#restXml",
        uri: "/test-bucket/test-key",
        headers: { "content-length": "2" },
        params: {
            Bucket: "test-bucket",
            Key: "test-key",
            ContentLength: 2,
            Body: "ab"
        }
    }
])
Loading