Skip to content

Harden regional authority validation - #650

Merged
Nilesh Choudhary (4gust) merged 2 commits into
mainfrom
4gust-split-region-validation
Aug 14, 2026
Merged

Nilesh Choudhary (4gust) merged 2 commits into
mainfrom
4gust-split-region-validation

Conversation

@4gust

Copy link
Copy Markdown
Collaborator

Summary

  • enforce lowercase ASCII DNS-label validation for explicit regional authorities
  • ignore invalid REGION_NAME and IMDS regions so discovery falls back to global behavior
  • cover DNS-label boundaries and invalid automatic-detection values

Testing

  • go test ./apps/internal/oauth/ops/authority -count=1

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ce37b127-6ff1-4e36-80e5-c74d574905ce
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ce37b127-6ff1-4e36-80e5-c74d574905ce
@sonarqubecloud

Copy link
Copy Markdown

@4gust
Nilesh Choudhary (4gust) merged commit 946d51a into main Aug 14, 2026
15 checks passed
Robbie-Microsoft added a commit that referenced this pull request Aug 18, 2026
origin/main gained "Harden regional authority validation (#650)", which tightens
validRegion to a DNS-label pattern, validates the caller-supplied region in
AADInstanceDiscovery and the IMDS response in parseRegionFromIMDSResponse, and
replaces detectRegion's normalization of REGION_NAME (strip spaces, lowercase)
with outright rejection of a value that is not a valid region.

CI builds refs/pull/632/merge, so it tested this combination while local
verification tested only the branch head. That is why
TestDetectRegionEnvironmentIsNotMemoized went red on CI while passing locally:
its second value, "WEST US 2", relied on the normalization #650 removed.

The three-way merge is textually clean because this branch's authority.go
changes are purely additive (70 insertions, 0 deletions) and never touch a line
#650 rewrote. The merged detectRegion therefore keeps upstream's validation of
the environment variable and this branch's memoization of the IMDS probe only.
Both properties are intended, and both are covered by tests.

Test changes:

- TestDetectRegionEnvironmentIsNotMemoized exists to pin that REGION_NAME is
  re-read rather than cached, which is orthogonal to normalization. Its second
  value becomes "westus2" and the now-false comment about spaces being stripped
  and the value lowercased is removed. The test still fails if memoization of
  the environment variable is reintroduced.

- TestDetectRegionBlankEnvironmentResolvesToNothing and, in the confidential
  package, acquireForRegionDiscovery both still pass, but for a different
  reason: a blank REGION_NAME is now rejected as invalid rather than stripped to
  empty. Their comments described the old mechanism and are corrected. What they
  assert is unchanged.

- Adds TestMtlsPoPInvalidForceRegionIsRejectedBeforeHTTP, the mTLS PoP analogue
  of #650's TestInvalidMSALForceRegionIsRejectedBeforeHTTP: an invalid
  MSAL_FORCE_REGION fails the acquisition before any request is made, with
  instance discovery disabled. MtlsTokenEndpoint interpolates the region into
  the token host without validating it, so this guarantee rests on endpoint
  resolution reaching AADInstanceDiscovery; the test pins it end to end rather
  than pinning that mechanism.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Robbie-Microsoft added a commit that referenced this pull request Aug 18, 2026
…he FIC branch

Brings in e17ec6d, which merged origin/main (946d51a, "Harden regional
authority validation (#650)") into #632. #650 replaced detectRegion's
space-stripping and lowercasing with strict validRegion rejection; the
parent already reconciled that against our memoization and fixed the test
that asserted the deleted stripping behavior, so nothing needed re-fixing
here.

No conflicts. Every file this merge touches -- authority.go,
authority_test.go, region_test.go, confidential_region_discovery_test.go,
confidential_test.go, and the new
confidential_mtls_region_validation_test.go -- is byte-identical to
e17ec6d, so the region reconciliation stays uniform across the stack.

The FIC branch's mTLS PoP ordering divergence is untouched: e17ec6d does
not modify confidential.go or confidential_mtls_validation_test.go, so
AuthorityInfo.ValidateMtlsPoP() still runs before prepareMtlsPoP, with the
comment explaining why, and both pins from e175bb9 still pass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

3 participants