Repository navigation
aws_sigv4: Fix ordering for headers with same prefix in the canonical request - #14370
austinmoore- wants to merge 1 commit into
Conversation
|
/cc @outscale-mgo |
8f344e6 to
18fe179
Compare
If a request containing two headers that have equivalent prefixes (ex. "x-amz-meta-test:test" and "x-amz-meta-test-two:test2") AWS expects the header with the shorter name to come first. The previous implementation used `strcmp` on the full header. Using the example, this would result in a comparison between the ':' and '-' chars and sort "x-amz-meta-test-two" before "x-amz-meta-test", which produces a different "StringToSign" than the one calculated by AWS.
|
Thanks! |
|
I took a look at the test case and I don't think it actually tests what the commit fixed. |
Problem
AWS SigV4 signing requires headers to be lexicographically ordered by name. The current implementation uses
strcmpon the full header, leading to incorrect ordering when header names have identical prefixes.I found two scenarios where curl users could be affected:
x-amz-meta-).x-amz-server-side-encryption-customer-keyandx-amz-server-side-encryption-customer-key-md5headers.Example of the issue:
curl -X PUT --verbose --silent \ --aws-sigv4 "aws:amz:us-east-1:s3" --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \ -H "x-amz-meta-test-two: Test2" \ -H "x-amz-meta-test: Test" \ --data-binary @testfile \ "https://examplebucket.s3.amazonaws.com/testfile"This results in
x-amz-meta-test-twoincorrectly precedingx-amz-meta-testin the canonical request, causing S3 to return aSignatureDoesNotMatcherror.Fix
This PR resolves the issue by:
strncmpwith the length of the shorter header name for comparison for the canonical request (actual request headers are left in the specified order).The fix has been verified with a few real S3 requests, along with the added libcurl test.