From a71ba38db719ece0294a74359ac740c2b5fc6d8d Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Fri, 11 Sep 2026 18:24:07 -0400 Subject: [PATCH] Improve remote prompt handling for `PSCredential` and `SecureString` arrays (#28007) --- .../engine/hostifaces/InternalHostUserInterface.cs | 13 +++++++++++-- .../remoting/common/WireDataFormat/RemoteHost.cs | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs index d8f2ef0bf..f4bc55a8f 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs @@ -666,12 +666,21 @@ namespace System.Management.Automation.Internal.Host internal static bool IsSecuritySensitiveType(string typeName) { - if (typeName.Equals(nameof(PSCredential), StringComparison.OrdinalIgnoreCase)) + string effectiveName = typeName; + int suffixIndex = effectiveName.IndexOfAny(new char[] { '[', ',' }); + if (suffixIndex >= 0) + { + effectiveName = effectiveName.Substring(0, suffixIndex); + } + + if (effectiveName.Equals(nameof(PSCredential), StringComparison.OrdinalIgnoreCase) || + effectiveName.Equals(typeof(PSCredential).FullName, StringComparison.OrdinalIgnoreCase)) { return true; } - if (typeName.Equals(nameof(SecureString), StringComparison.OrdinalIgnoreCase)) + if (effectiveName.Equals(nameof(SecureString), StringComparison.OrdinalIgnoreCase) || + effectiveName.Equals(typeof(SecureString).FullName, StringComparison.OrdinalIgnoreCase)) { return true; } diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHost.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHost.cs index 79b920c22..f0a6649fe 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHost.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHost.cs @@ -379,12 +379,13 @@ namespace System.Management.Automation.Remoting Type fieldType = InternalHostUserInterface.GetFieldType(fieldDesc); if (fieldType != null) { - if (fieldType == typeof(PSCredential)) + Type effectiveType = fieldType.IsArray ? fieldType.GetElementType() : fieldType; + if (effectiveType == typeof(PSCredential)) { havePSCredential = true; fieldDesc.ModifiedByRemotingProtocol = true; } - else if (fieldType == typeof(System.Security.SecureString)) + else if (effectiveType == typeof(System.Security.SecureString)) { prerequisiteCalls.Add(ConstructWarningMessageForSecureString( computerName, RemotingErrorIdStrings.RemoteHostPromptSecureStringPrompt));