azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzIpGroup missing input validation

Open dancs85 opened this issue 6 years ago • 7 comments

Description

New-AzIpGroup is missing input validation on the Name parameter, in that it accepts strings with invalid characters (like Space). The Azure REST API response returns a non-descriptive error when invalid characters are used.

Steps to reproduce

Failure:

New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG" -IpAddress 1.1.1.1/32 -Location 'Australia East'

Success:

New-AzIpGroup -Name "BrisbaneOffice" -ResourceGroupName "testRG" -IpAddress 1.1.1.1/32 -Location 'Australia East'

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.18362.628
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.628
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.7.2      Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script     2.3.1      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSetting, Add-AzApplicationGatewayCustomError...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}

Debug output

DEBUG: 12:10:00 PM - NewIpGroupsCommand begin processing with ParameterSet 'Default'.
DEBUG: 12:10:00 PM - using account id '[email protected]'...
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', Endpoint: 'https://login.microsoftonline.com/', ClientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', ClientRedirect:
 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version
'2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version
'2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: === Token Acquisition started:
 CacheType: null
 Authentication Target: User
 , Authority Host: login.microsoftonline.com
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: === Token Acquisition started:
 Authority: https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: null
 Authentication Target: User

DEBUG: [ADAL]: Verbose: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: Loading from cache.
DEBUG: [ADAL]: Verbose: 2020-02-21T02:10:00.1613080Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: Loading from cache.
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1623076Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 2 items to token cache.
DEBUG: [ADAL]: Verbose: 2020-02-21T02:10:00.1623076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: Looking up cache for a token...
DEBUG: [ADAL]: Verbose: 2020-02-21T02:10:00.1623076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: Looking up cache for a token...
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1623076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: 41.4937282066667 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: 41.4937282066667 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 21/02/2020 2:51:29 AM +00:00
DEBUG: [ADAL]: Information: 2020-02-21T02:10:00.1633076Z: f83c9456-cc84-4e4f-bd8a-8aa051565037 - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 21/02/2020 2:51:29 AM
+00:00Access Token Hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  User id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '02/21/2020 02:51:29 +00:00', MultipleResource? 'True', Tenant: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', UserId: '[email protected]'
DEBUG: [Common.Authentication]: User info for token DisplayId: '[email protected]', Name: First Last, IdProvider: 'https://sts.windows.net/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/', Uid:
'5c1b4a95-760f-4e45-b3ea-364c1b683ef0'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '02/21/2020 02:51:29 +00:00' Comparing to '02/21/2020 02:10:00 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:41:29.6226922'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Network/ipGroups/Brisbane Office?api-version=2019-11-01

Headers:
x-ms-client-request-id        : 6d12eecf-c1ad-4c78-b946-4b92c1496c59
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-reads: 11998
x-ms-request-id               : f3ab17a9-2b79-43ff-aecd-77eb47ff57f7
x-ms-correlation-request-id   : f3ab17a9-2b79-43ff-aecd-77eb47ff57f7
x-ms-routing-request-id       : AUSTRALIAEAST:20200221T021000Z:f3ab17a9-2b79-43ff-aecd-77eb47ff57f7
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Fri, 21 Feb 2020 02:09:59 GMT
Server                        : Microsoft-HTTPAPI/2.0

Body:
Invalid resource name Brisbane%20Office.

New-AzIpGroup : Unable to deserialize the response.
At line:1 char:1
+ New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzIpGroup], SerializationException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.NewIpGroupsCommand

DEBUG: AzureQoSEvent: CommandName - New-AzIpGroup; IsSuccess - False; Duration - 00:00:01.5740997;; Exception - Microsoft.Rest.SerializationException: Unable to deserialize the response. ---> Newtonsoft.Json.JsonReaderException: Error
parsing Infinity value. Path '', line 1, position 2.
   at Newtonsoft.Json.JsonTextReader.ParseNumberPositiveInfinity(ReadType readType, Boolean matched)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject[T](String json, JsonSerializerSettings settings)
   at Microsoft.Azure.Management.Network.IpGroupsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Management.Network.IpGroupsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Azure.Management.Network.IpGroupsOperationsExtensions.<GetAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Management.Network.IpGroupsOperationsExtensions.Get(IIpGroupsOperations operations, String resourceGroupName, String ipGroupsName, String expand)
   at Microsoft.Azure.Commands.Network.IpGroupBaseCmdlet.GetIpGroup(String resourceGroupName, String name)
   at Microsoft.Azure.Commands.Network.IpGroupBaseCmdlet.IsIpGroupsPresent(String resourceGroupName, String name)
   at Microsoft.Azure.Commands.Network.NewIpGroupsCommand.Execute()
   at Microsoft.Azure.Commands.Network.NetworkBaseCmdlet.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 12:10:02 PM - NewIpGroupsCommand end processing.

Error output

Message        : Unable to deserialize the response.
StackTrace     :    at Microsoft.Azure.Management.Network.IpGroupsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
                    at Microsoft.Azure.Management.Network.IpGroupsOperationsExtensions.<GetAsync>d__1.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
                    at Microsoft.Azure.Management.Network.IpGroupsOperationsExtensions.Get(IIpGroupsOperations operations, String resourceGroupName, String ipGroupsName, String expand)
                    at Microsoft.Azure.Commands.Network.IpGroupBaseCmdlet.GetIpGroup(String resourceGroupName, String name)
                    at Microsoft.Azure.Commands.Network.IpGroupBaseCmdlet.IsIpGroupsPresent(String resourceGroupName, String name)
                    at Microsoft.Azure.Commands.Network.NewIpGroupsCommand.Execute()
                    at Microsoft.Azure.Commands.Network.NetworkBaseCmdlet.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Microsoft.Rest.SerializationException
InvocationInfo : {New-AzIpGroup}
Line           : New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG" -IpAddress 1.1.1.1/32 -Location 'Australia East'
Position       : At line:1 char:1
                 + New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 19

Message        : Error parsing Infinity value. Path '', line 1, position 2.
StackTrace     :    at Newtonsoft.Json.JsonTextReader.ParseNumberPositiveInfinity(ReadType readType, Boolean matched)
                    at Newtonsoft.Json.JsonTextReader.ParseValue()
                    at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
                    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
                    at Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject[T](String json, JsonSerializerSettings settings)
                    at Microsoft.Azure.Management.Network.IpGroupsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
Exception      : Newtonsoft.Json.JsonReaderException
InvocationInfo : {New-AzIpGroup}
Line           : New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG" -IpAddress 1.1.1.1/32 -Location 'Australia East'
Position       : At line:1 char:1
                 + New-AzIpGroup -Name "Brisbane Office" -ResourceGroupName "testRG ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 19

dancs85 avatar Feb 21 '20 02:02 dancs85

Hi @dancs85 thanks a lot for your feedback! Your information is very valueful to us. I'm forwarding this issue to Network team.

wyunchi-ms avatar Feb 21 '20 08:02 wyunchi-ms

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub

ghost avatar Feb 21 '20 08:02 ghost

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub

ghost avatar Feb 21 '20 08:02 ghost

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc

ghost avatar Feb 25 '20 17:02 ghost

@dancs85, attempting to repro now

allegradomel avatar Feb 25 '20 19:02 allegradomel

Was able to repro, believe this belongs to the Firewall team, reassigning

allegradomel avatar Feb 25 '20 19:02 allegradomel

Thanks for reporting. We will get that fixed.

yairt1974 avatar May 31 '20 21:05 yairt1974