Skip to content

Commit 83c102f

Browse files
committed
Explicitly rejecting empty hostname
This is not a breaking change, because the pre-existing implementation will error out anyway, but with a less meaningful exception.
1 parent 85c0f06 commit 83c102f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

msal/authority.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def user_realm_discovery(self, username, correlation_id=None, response=None):
178178
def canonicalize(authority_or_auth_endpoint):
179179
# Returns (url_parsed_result, hostname_in_lowercase, tenant)
180180
authority = urlparse(authority_or_auth_endpoint)
181-
if authority.scheme == "https":
181+
if authority.scheme == "https" and authority.hostname:
182182
parts = authority.path.split("/")
183183
first_part = parts[1] if len(parts) >= 2 and parts[1] else None
184184
if authority.hostname.endswith(_CIAM_DOMAIN_SUFFIX): # CIAM
@@ -192,7 +192,7 @@ def canonicalize(authority_or_auth_endpoint):
192192
return authority, authority.hostname, parts[1]
193193
raise ValueError(
194194
"Your given address (%s) should consist of "
195-
"an https url with a minimum of one segment in a path: e.g. "
195+
"an https url with hostname and a minimum of one segment in a path: e.g. "
196196
"https://login.microsoftonline.com/{tenant} "
197197
"or https://{tenant_name}.ciamlogin.com/{tenant} "
198198
"or https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/policy"

tests/test_authority.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def test_canonicalize_rejects_tenantless_host_with_trailing_slash(self):
190190
with self.assertRaises(ValueError):
191191
canonicalize("https://no.tenant.example.com/")
192192

193+
def test_canonicalize_rejects_empty_host(self):
194+
with self.assertRaises(ValueError):
195+
canonicalize("https:///tenant")
196+
193197

194198
@unittest.skipIf(os.getenv("TRAVIS_TAG"), "Skip network io during tagged release")
195199
class TestAuthorityInternalHelperUserRealmDiscovery(unittest.TestCase):

0 commit comments

Comments
 (0)