Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't sign Expect header in SigV4 #812

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/d4ba7f85-24f3-4925-8bb4-25020f294b9a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "d4ba7f85-24f3-4925-8bb4-25020f294b9a",
"type": "bugfix",
"description": "Skip signing the `Expect` header in SigV4",
"issues": [
"awslabs/aws-sdk-kotlin#862"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ internal interface Canonicalizer {
): CanonicalRequest
}

// Taken from https://github.com/awslabs/aws-c-auth/blob/31d573c0dd328db5775f7a55650d27b8c08311ba/source/aws_signing.c#L118-L151
// Taken from https://github.com/awslabs/aws-c-auth/blob/dd505b55fd46222834f35c6e54165d8cbebbfaaa/source/aws_signing.c#L118-L156
private val skipHeaders = setOf(
"connection",
"expect", // https://github.com/awslabs/aws-sdk-kotlin/issues/862
"sec-websocket-key",
"sec-websocket-protocol",
"sec-websocket-version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,37 @@ class DefaultCanonicalizerTest {

assertEquals("/2013-04-01/healthcheck/foo%253Cbar%253Ebaz%253C%252Fbar%253E", uri.canonicalPath(config))
}

@Test
fun testUnsignedHeaders() = runTest {
val request = HttpRequest {
method = HttpMethod.GET
url { host = Host.Domain("bar.amazonaws.com") }
headers {
// These should be signed
set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
set("x-amz-user-agent", "baz")

// These should not be signed
set("Expect", "100-continue")
set("X-Amzn-Trace-Id", "qux")
}
body = HttpBody.Empty
}

val signingDateString = "20150830T123600Z"
val config = AwsSigningConfig {
region = "foo"
service = "bar"
signingDate = Instant.fromIso8601(signingDateString)
credentialsProvider = testCredentialsProvider
}
val credentials = Credentials("foo", "bar") // anything without a session token set

val canonicalizer = Canonicalizer.Default
val actual = canonicalizer.canonicalRequest(request, config, credentials)

val expectedSignedHeaders = "content-type;host;x-amz-date;x-amz-user-agent"
assertEquals(expectedSignedHeaders, actual.signedHeaders)
}
}