Skip to content

Commit

Permalink
fix: canonical request path if empty choose '/'
Browse files Browse the repository at this point in the history
additionally this PR allows content-type and
content-length to be part of signed headers as
this is allowed in signature v4.
  • Loading branch information
harshavardhana authored and minio-trusted committed Nov 24, 2021
1 parent 77c3e40 commit a425458
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion minio/credentials/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(
self._body = urlencode(query_params)
self._content_sha256 = sha256_hash(self._body)
url = urlsplit(sts_endpoint)
self._url = url
self._host = url.netloc
if (
(url.scheme == "http" and url.port == 80) or
Expand All @@ -131,7 +132,7 @@ def retrieve(self):
utctime = utcnow()
headers = sign_v4_sts(
"POST",
urlsplit(self._sts_endpoint),
self._url,
self._region,
{
"Content-Type": "application/x-www-form-urlencoded",
Expand Down
7 changes: 3 additions & 4 deletions minio/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def _get_canonical_headers(headers):
for key, values in headers.items():
key = key.lower()
if key not in (
"authorization", "content-type",
"content-length", "user-agent",
"authorization",
"user-agent",
):
values = values if isinstance(values, (list, tuple)) else [values]
canonical_headers[key] = ",".join([
Expand Down Expand Up @@ -91,7 +91,6 @@ def _get_canonical_request_hash(method, url, headers, content_sha256):
"""Get canonical request hash."""
canonical_headers, signed_headers = _get_canonical_headers(headers)
canonical_query_string = _get_canonical_query_string(url.query)

# CanonicalRequest =
# HTTPRequestMethod + '\n' +
# CanonicalURI + '\n' +
Expand All @@ -101,7 +100,7 @@ def _get_canonical_request_hash(method, url, headers, content_sha256):
# HexEncode(Hash(RequestPayload))
canonical_request = (
f"{method}\n"
f"{url.path}\n"
f"{url.path or '/'}\n"
f"{canonical_query_string}\n"
f"{canonical_headers}\n\n"
f"{signed_headers}\n"
Expand Down

0 comments on commit a425458

Please sign in to comment.