Skip to content

Validate region string format in AADInstanceDiscovery#625

Open
bgavrilMS wants to merge 1 commit into
mainfrom
fix/validate-region-string
Open

Validate region string format in AADInstanceDiscovery#625
bgavrilMS wants to merge 1 commit into
mainfrom
fix/validate-region-string

Conversation

@bgavrilMS
Copy link
Copy Markdown
Member

Fixes #624

Problem

AADInstanceDiscovery uses the region string directly in URL construction (https://{region}.{host}/...) without validating its format. Malformed region values containing dots, slashes, or other special characters could produce incorrect URLs.

Solution

Added a regex validation (^[a-z][a-z0-9-]*$) that checks the region string before it is used in URL construction. This matches the Azure region naming convention (e.g., eastus, westus2, east-us-2). If the region is invalid, a clear error is returned.

Changes

  • Added regexp import
  • Added validRegion compiled regex at package level
  • Added validation check in AADInstanceDiscovery before URL interpolation

Add regex validation (^[a-z][a-z0-9-]*$) for the region string before
it is used in URL construction. Returns a clear error if the region
contains unexpected characters such as dots, slashes, or uppercase.

Fixes #624

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@@ -592,6 +596,9 @@ func (c Client) AADInstanceDiscovery(ctx context.Context, authorityInfo Info) (I
region = detectRegion(ctx)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We return error even when detected region is not valid ?

user input -> check - > pass or return error
auto detect -> check -> pass or silent fall ?

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.

Validate region string in AADInstanceDiscovery

2 participants