Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,21 @@ internal static Type GetFieldType(FieldDescription field)

internal static bool IsSecuritySensitiveType(string typeName)
{
if (typeName.Equals(nameof(PSCredential), StringComparison.OrdinalIgnoreCase))
string effectiveName = typeName;
int suffixIndex = effectiveName.IndexOfAny(new char[] { '[', ',' });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra allocation.

Suggested change
int suffixIndex = effectiveName.IndexOfAny(new char[] { '[', ',' });
int suffixIndex = effectiveName.IndexOfAny('[', ',');

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,13 @@ internal Collection<RemoteHostCall> PerformSecurityChecksOnHostMessage(string co
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));
Expand Down
Loading