okigan / awscurl

curl-like access to AWS resources with AWS Signature Version 4 request signing.
MIT License
735 stars 91 forks source link

awscurl generates an incorrect request signature when user-supplied hostname includes capital letters. #186

Closed bfrobin446 closed 8 months ago

bfrobin446 commented 8 months ago

The command awscurl --service sts -X POST -d 'Action=GetCallerIdentity&Version=2011-06-15' -H 'Content-Type: application/x-www-form-urlencoded' https://sts.us-east-1.amazonaws.com successfully calls the GetCallerIdentity operation and returns a response.

If I change the URL by capitalizing some of the letters in the hostname, awscurl --service sts -X POST -d 'Action=GetCallerIdentity&Version=2011-06-15' -H 'Content-Type: application/x-www-form-urlencoded' https://STS.us-east-1.amazonaws.com, I get a SignatureDoesNotMatch error.

The code apparently assumes that the header values are already in their canonical form at the point where a comment describes how to canonicalize them (https://github.com/okigan/awscurl/blob/b2ebe710877e7da93470001ea63b0f546b0abb0e/awscurl/awscurl.py#L198), but a mixed-case hostname reaches this point without ever being lowercased.