From fafc141a0578150f63d8823e6117a70a91bcdf34 Mon Sep 17 00:00:00 2001 From: Phil Grayson Date: Wed, 15 Jun 2022 23:30:14 +0100 Subject: [PATCH] Fix for changes in urlsplit urlsplit function was changed to strip ASCII newline and tab characters in https://github.com/python/cpython/pull/25595. The change causes this plugin to not properly authenticate with S3, since a required newline character is no longer present. This issue was identified on Amazon Linux 2 Python distribution which backported the change to Python 2. https://alas.aws.amazon.com/AL2/ALAS-2022-1802.html. urlsplit behaviour before the fix. ``` Python 2.7.18 (default, Jun 10 2021, 00:11:02) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from urlparse import urlsplit >>> urlsplit("http://localhost/some-path/n").path '/some-path\n' >>> ``` urlsplit behaviour after the fix. ``` Python 2.7.18 (default, May 25 2022, 14:30:51) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from urlparse import urlsplit >>> urlsplit("http://localhost/some-path/n").path '/some-path' >>> ``` --- cob.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cob.py b/cob.py index 0510731..394cd41 100644 --- a/cob.py +++ b/cob.py @@ -160,7 +160,8 @@ def signed_headers(self, headers_to_sign): def canonical_request(self, request): cr = [request.method.upper()] path = self._normalize_url_path(urlsplit(request.url).path) - cr.append(path) + # "\n" in the url, required by AWS S3 Auth v4 + cr.append(path.rstrip() + "\n") headers_to_sign = self.headers_to_sign(request) cr.append(self.canonical_headers(headers_to_sign) + '\n') cr.append(self.signed_headers(headers_to_sign)) @@ -524,8 +525,7 @@ def set_credentials(self): def fetch_headers(self, url, path): headers = {} - # "\n" in the url, required by AWS S3 Auth v4 - url = urlparse.urljoin(url, urllib2.quote(path)) + "\n" + url = urlparse.urljoin(url, urllib2.quote(path)) credentials = Credentials(self.access_key, self.secret_key, self.token) request = HTTPRequest("GET", url) signer = S3SigV4Auth(credentials, "s3", self.region, self.conduit)