-
Notifications
You must be signed in to change notification settings - Fork 157
Validate region string format before use in URL construction #1028
Copy link
Copy link
Open
Labels
EnhancementA request or suggestion to improve some aspect of the libraryA request or suggestion to improve some aspect of the libraryP2Normal priority items, should be done after P1Normal priority items, should be done after P1confidential-clientFor issues related to confidential client appsFor issues related to confidential client appspublic-clientFor questions/issues related to public client appsFor questions/issues related to public client apps
Metadata
Metadata
Assignees
Labels
EnhancementA request or suggestion to improve some aspect of the libraryA request or suggestion to improve some aspect of the libraryP2Normal priority items, should be done after P1Normal priority items, should be done after P1confidential-clientFor issues related to confidential client appsFor issues related to confidential client appspublic-clientFor questions/issues related to public client appsFor questions/issues related to public client apps
Type
Fields
Give feedbackNo fields configured for issues without a type.
The
discoverRegionmethod inAadInstanceDiscoveryProvider.javareturns the region string from either theREGION_NAMEenvironment variable or the IMDS endpoint response without validating its format. This region is then used ingetRegionalizedHostto construct authority URLs via string replacement (e.g.,{region}.login.microsoft.com).If the region string contains unexpected characters (dots, slashes, etc.), the resulting URL could be malformed and lead to failed or misdirected requests.
Azure region names follow a consistent pattern of lowercase alphanumeric characters and hyphens (e.g.,
eastus,westus2,east-us-2).Proposed fix: Validate the region string against a pattern like
^[a-z][a-z0-9-]*$at discovery time (indiscoverRegion) and treat invalid values as if no region was detected.Reference: MSAL .NET already validates regions via
RegionManager.ValidateRegion(). MSAL Go added validation in AzureAD/microsoft-authentication-library-for-go#625.