Skip to content

Commit

Permalink
Expand skipped headers for sigv4 canonical request signing to include…
Browse files Browse the repository at this point in the history
… x-amzn-trace-id and authorization headers.
  • Loading branch information
Sam Bartlett committed Jun 28, 2023
1 parent 8663237 commit 25e7b23
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# author = "rcoh"

[[aws-sdk-rust]]
message = "Automatically exclude x-ray trace id headers and authorization headers from Sigv4 canonical request calculations."
references = ["smithy-rs#2813"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
message = "Automatically exclude X-Ray trace ID headers and authorization headers from SigV4 canonical request calculations."
references = ["smithy-rs#2815"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "relevantsam"

[[aws-sdk-rust]]
Expand Down
30 changes: 30 additions & 0 deletions aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,36 @@ mod tests {
assert_eq!(creq.values.signed_headers().as_str(), "host;x-amz-date");
}

// It should exclude authorization, user-agent, x-amzn-trace-id headers from presigning
#[test]
fn non_presigning_header_exclusion() {
let request = http::Request::builder()
.uri("https://some-endpoint.some-region.amazonaws.com")
.header("authorization", "test-authorization")
.header("content-type", "application/xml")
.header("content-length", "0")
.header("user-agent", "test-user-agent")
.header("x-amzn-trace-id", "test-trace-id")
.header("x-amz-user-agent", "test-user-agent")
.body("")
.unwrap();
let request = SignableRequest::from(&request);

let settings = SigningSettings {
signature_location: SignatureLocation::Headers,
..Default::default()
};

let signing_params = signing_params(settings);
let canonical = CanonicalRequest::from(&request, &signing_params).unwrap();

let values = canonical.values.as_headers().unwrap();
assert_eq!(
"content-length;content-type;host;x-amz-date;x-amz-user-agent",
values.signed_headers.as_str()
);
}

// It should exclude authorization, user-agent, x-amz-user-agent, x-amzn-trace-id headers from presigning
#[test]
fn presigning_header_exclusion() {
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-sigv4/src/http_request/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;
/// HTTP signing parameters
pub type SigningParams<'a> = crate::SigningParams<'a, SigningSettings>;

const X_RAY_TRACE_HEADER: &str = "x-amzn-trace-id";
const X_RAY_TRACE_HEADER: HeaderName = HeaderName::from_static("x-amzn-trace-id");

/// HTTP-specific signing settings
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Default for SigningSettings {
// Changes when sent by proxy
USER_AGENT,
// Changes based on the request from the client
HeaderName::from_static(X_RAY_TRACE_HEADER),
X_RAY_TRACE_HEADER,
]
.to_vec();

Expand Down

0 comments on commit 25e7b23

Please sign in to comment.