Skip to content

Fixed the Cross Cloud OIDC fix #916

Open
4gust wants to merge 1 commit into
devfrom
4gust/oidc-crosscloud-fix
Open

Fixed the Cross Cloud OIDC fix #916
4gust wants to merge 1 commit into
devfrom
4gust/oidc-crosscloud-fix

Conversation

@4gust
Copy link
Copy Markdown
Contributor

@4gust 4gust commented May 12, 2026

This pull request significantly refactors and strengthens the handling of Microsoft cloud authorities in msal/authority.py. The main improvements are the introduction of a robust mechanism to determine and validate whether authority and endpoint hosts belong to the same sovereign cloud, stricter issuer validation logic, and better prevention of cross-cloud misconfigurations. These changes enhance security, maintainability, and clarity of authority host management.

Cloud authority management and validation:

  • Introduced a new mapping system (_HOSTS_BY_CLOUD, _KNOWN_HOST_TO_CLOUD, etc.) to centrally define and manage all known Microsoft cloud authority hosts, their aliases, and their mapping to logical cloud identifiers, with runtime checks for duplicates.
  • Added the _resolve_known_cloud function to determine the logical cloud for a given host, including support for regional subdomains, and _are_in_same_cloud to check if two hosts belong to the same cloud.

Endpoint and issuer security enhancements:

  • Implemented _ensure_endpoint_same_cloud_as_authority to enforce that OIDC discovery endpoints (token, authorization, device endpoints) must reside in the same cloud as the authority, raising a clear error if not. This is now called during authority initialization for OIDC authorities.
  • Refactored has_valid_issuer with a clear, ordered set of validation steps, including exact match, same host/scheme, CIAM tenant pattern, same cloud checks, region-shaped prefix, and B2C subdomain handling, closely following MSAL.NET's security model.

Miscellaneous:

  • Added regular expression-based validation for regional prefixes and improved comments/documentation throughout for maintainability and clarity.

These changes collectively harden the library against misconfiguration and cross-cloud authority/endpoint mismatches, and make future updates to cloud authority logic easier and safer.

Copilot AI review requested due to automatic review settings May 12, 2026 10:44
@4gust 4gust requested a review from a team as a code owner May 12, 2026 10:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens msal/authority.py around OIDC authority validation to prevent cross-sovereign-cloud misconfigurations by introducing a centralized cloud/host mapping, new host-to-cloud resolution helpers, stricter issuer-validation ordering, and an explicit same-cloud enforcement for OIDC discovery endpoints. It also adds extensive test coverage to validate the new issuer/cloud/endpoint behaviors and key regressions (including the referenced #5927 scenario).

Changes:

  • Introduces cloud sentinel constants and host→cloud mappings, plus _resolve_known_cloud(), _are_in_same_cloud(), and _ensure_endpoint_same_cloud_as_authority() to centralize and enforce cloud logic.
  • Refactors Authority.has_valid_issuer() into ordered validation steps (exact match, same host, CIAM tenant pattern, same-cloud rules, regional-prefix rules, B2C subdomain rules).
  • Adds a large suite of tests covering same-cloud alias acceptance, cross-cloud rejection, regional host handling, CIAM tenant-pattern validation, and endpoint same-cloud enforcement.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
msal/authority.py Adds cloud mapping + helpers and tightens issuer/endpoint validation to block cross-cloud OIDC discovery data.
tests/test_authority.py Adds comprehensive regression/unit tests for issuer validation and endpoint same-cloud enforcement across clouds/aliases/regions/CIAM.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread msal/authority.py
Comment on lines +401 to +405
if issuer_host.endswith(_CIAM_DOMAIN_SUFFIX):
issuer_tenant = issuer_host[:-len(_CIAM_DOMAIN_SUFFIX)]
auth_path_parts = [p for p in authority_parsed.path.split("/") if p]
if auth_path_parts:
authority_tenant = auth_path_parts[0].lower()
Comment thread msal/authority.py
authority_host = authority_parsed.hostname.lower() if authority_parsed.hostname else ""
if potential_base == authority_host:
return True
if (_REGION_PREFIX_PATTERN.match(prefix)
Comment thread msal/authority.py
Comment on lines +440 to +443
if any(
issuer_host.endswith("." + h)
for h in WELL_KNOWN_B2C_HOSTS
if h != "ciamlogin.com"):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants