tedder / requests-aws4auth

Amazon Web Services version 4 authentication for the Python Requests module
MIT License
178 stars 62 forks source link

Issue with Signing AWS Requests for Paths Starting with Double Slash #69

Open OfirSWiz opened 1 year ago

OfirSWiz commented 1 year ago

I have encountered an issue while using the library to sign AWS request, specifically when the requests start with a double slash (e.g., when an object in S3 contains a forward slash '/'). After investigating the source code, it appears that the problem lies in the amz_cano_path function, which incorrectly replaces double slashes with a single slash.

Expected Behavior: The library should correctly handle paths starting with a double slash and generate valid signatures for AWS requests without altering the path.

Proposed Solution: To address this issue, I suggest modifying the amz_cano_path function to correctly handle paths starting with a double slash. The function should preserve the original path without replacing double slashes with a single slash. This could be fixed by removing the following line fixed_path = re.sub('/+', '/', fixed_path)

tedder commented 1 year ago

Interesting discovery. Probably right not to double it, though I wonder if that'll cause a regression. Feel free to contribute a PR (especially if there's a unit test).