Repository navigation
Conversation
The SigV4 canonical request "Trimall" step turns sequential whitespace inside a header value into a single space. libcloud only stripped the ends of the value, so a signed header such as S3 user metadata with two spaces or a tab produced a different signature than the server computed and the request failed with SignatureDoesNotMatch. Join the whitespace-separated parts with a single space, as botocore does, and add a test with expected values taken from botocore. Signed-off-by: Dezhen Lu <dezhen.lu@student.uni-tuebingen.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
AWSRequestSignerAlgorithmV4._get_canonical_headers()only strips leading and trailing whitespace from header values. The SigV4 spec ("Trimall") also turns sequential whitespace inside a value into a single space. botocore does this, and so does at least one S3-compatible server (MinIO). So when a signed header value has two spaces or a tab in it, libcloud signs a different canonical request than the server computes, and the request is rejected withSignatureDoesNotMatch. There is an old TODO about this intest_aws.py.Since the V4 signer signs every request header, the easiest way to hit this is S3 user metadata:
How I found it
I compared the canonical request libcloud builds with the one botocore builds (
S3SigV4Auth.canonical_request) for the same request. They only differed when a header value had sequential spaces or a tab:Then I checked against a real server (a local MinIO, through the MinIO driver). On trunk, uploads with
"a b"or"a\tb"in metadata fail withSignatureDoesNotMatch, while"a b"works. botocore uploads all three values to the same server fine. With this change all three uploads succeed through libcloud too.Where this can show up in practice
Any S3 (or S3-compatible) upload where metadata comes from user input or file attributes, e.g. a description or an original filename with a double space or a tab. Other V4-signed requests with such header values are affected the same way.
Change
Header values are now built with
" ".join(str(v).split()), which matches botocore. I added a test with expected values taken from botocore's canonical headers (it fails on trunk and passes with the fix), removed the old TODO comment, and added a CHANGES.rst entry.libcloud/test/common/test_aws.py,test_s3.py,test_minio.pyandtest_ec2.pypass locally (1298 passed, 1 skipped).The old TODO mentioned an exception for quoted strings. botocore collapses whitespace inside quotes too (
'"a b"'becomes"a b"), and MinIO accepts that signature, so I didn't add an exception.Status
Checklist (tick everything that applies)
This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.