Skip to content

Commit

Permalink
Strip port 80/443 from host
Browse files Browse the repository at this point in the history
Supplying port 80 or 443 with host (ex. `storage.googleapis.com:443`) fails in v4 signing. Remove these default ports to prevent signature matching failure.

Similar issue:
aws/aws-cli#2883
  • Loading branch information
edward-codecov authored Sep 26, 2019
1 parent 3380d0f commit f2286f6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions minio/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def presign_v4(method, url, access_key, secret_key, session_token=None,

parsed_url = urlsplit(url)
content_hash_hex = _UNSIGNED_PAYLOAD
host = parsed_url.netloc
host = remove_default_port(parsed_url)
headers['Host'] = host
iso8601Date = request_date.strftime("%Y%m%dT%H%M%SZ")

Expand Down Expand Up @@ -208,7 +208,7 @@ def sign_v4(method, url, region, headers=None,
# with no payload, calculate sha256 for 0 length data.
content_sha256 = get_sha256_hexdigest('')

host = parsed_url.netloc
host = remove_default_port(parsed_url)
headers['Host'] = host

date = datetime.utcnow()
Expand Down Expand Up @@ -355,3 +355,10 @@ def generate_authorization_header(access_key, date, region,
'SignedHeaders=' + signed_headers_string + ',',
'Signature=' + signature]
return ' '.join(auth_header)

def remove_default_port(parsed_url):
if parsed_url.port is 80 or 443:
host = parsed_url.hostname
else:
host = parsed_url.netloc
return host

0 comments on commit f2286f6

Please sign in to comment.