-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Describe the bug
Minor issue, but I discovered some bad input handling for az role commands that causes the command to hang or throw an unhandled error or an unexpected error. The bad input causes these unexpected behaviors when any string contains {x[]}, with any combination or permutation of extra characters, to hang forever. It seems the x can be any alphabet. You can also pass {[]} for Azure CLI to throw various uncaught errors. This seems to affect any command with a --scope parameter.
Passing {x[]} causes the command to hang and never return:
az role assignment create --role Reader --scope "{x[]}" --assignee <assignee username> --description "test description"
az role definition list --scope "{x[]}"
az ad sp create-for-rbac -n MyApp --role Contributor --scopes "{x[]}"
Passing {[]} gives miscellaneous errors that may or may not be handled:
az role assignment create --role Reader --scope "{[]}" --assignee <assignee username> --description "test description"
az role definition list --scope "{[]}"`
az ad sp create-for-rbac -n MyApp --role Contributor --scopes "{[]}"
This affects the user because the user might accidentally run something like this in PowerShell, for example:
az role definition list --scope /subscriptions/$account.id
The --scope parameter value above is expanded into to something like the following (anything like <*> can be ignored, and is added to describe the values that should be there):
/subscriptions/@{environmentName=myEnv; homeTenantId=<home tenant ID>; id=<ID>; isDefault=True; managedByTenants=System.Object[]; name=System Subscription; state=Enabled; tenantId=<tenant ID>; user=}.id
The above expansion contains the pattern {x[]}, which will cause the execution to hang forever, even though the user is at fault.
Related command
Any command with a --scope parameter.
Errors
Hangs forever, or various errors depending on the command.
Issue script & Debug output
The commands hang and throw various errors depending on the command.
Expected behavior
Should not hang, and the bad --scope input should be handled properly if possible, but at the very least it should not hang.
Environment Summary
(env) PS C:\Users\Administrator\Desktop> az --version
azure-cli 2.55.0
core 2.55.0
telemetry 1.1.0
Dependencies:
msal 1.24.0b2
azure-mgmt-resource 23.1.0b2
Python location 'C:\Users\Administrator\Desktop\env\Scripts\python.exe'
Extensions directory 'C:\Users\Administrator\.azure\cliextensions'
Python (Windows) 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
Additional context
No response