From 59c30c50daf9fc15332b64748eb3d5ee5e5d5507 Mon Sep 17 00:00:00 2001 From: Florent Viard Date: Fri, 20 Mar 2020 17:31:57 +0100 Subject: [PATCH] Fixes #1059 - Hack for SignatureDoesNotMatch error when host port 80 or 443 is specified, due to stupid servers This hack is needed because it looks like that some servers are not respecting the HTTP spec, and so will fail the signature check if the port is specified in the "Host" header for default ports. STUPIDIEST THING EVER FOR A SERVER but looks like that it is common ... More details here: https://github.com/minio/minio/issues/9169 --- S3/S3.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/S3/S3.py b/S3/S3.py index f5006fef3..e6ca91b14 100644 --- a/S3/S3.py +++ b/S3/S3.py @@ -272,6 +272,17 @@ def get_hostname(self, bucket): host = getHostnameFromBucket(bucket) else: host = self.config.host_base.lower() + # The following hack is needed because it looks like that some servers + # are not respecting the HTTP spec and so will fail the signature check + # if the port is specified in the "Host" header for default ports. + # STUPIDIEST THING EVER FOR A SERVER... + # See: https://github.com/minio/minio/issues/9169 + if self.config.use_https: + if host.endswith(':443'): + host = host[:-4] + elif host.endswith(':80'): + host = host[:-3] + debug('get_hostname(%s): %s' % (bucket, host)) return host