Skip to content

Bad input handling for --scope parameter #28077

@TheOnlyWei

Description

@TheOnlyWei

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

Metadata

Metadata

Assignees

Labels

Auto-AssignAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamGraphaz adOKR CandidateThis label is used to track how many GitHub issues we have resolved for OKR purpose.RBACaz roleneeds-author-feedbackMore information is needed from author to address the issue.no-recent-activityThere has been no recent activity on this issue.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions