Skip to content

Commit 306e332

Browse files
authored
Make secrets detection option enabled by default and improve the feature (#24874)
1 parent 90f8082 commit 306e332

File tree

7 files changed

+22
-14
lines changed

7 files changed

+22
-14
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Enabled secrets detection option by default.
2223
* Fixed a null reference issue during the process of `Get-AzContext -ListAvailable` [#24854].
2324
* Supported interactive subscription selection for user login flow. See more details at [Announcing a new login experience with Azure PowerShell and Azure CLI
2425
](https://techcommunity.microsoft.com/t5/azure-tools-blog/announcing-a-new-login-experience-with-azure-powershell-and/ba-p/4109357)

src/Accounts/Authentication/Config/ConfigInitializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private void RegisterConfigs(IConfigManager configManager)
235235
configManager.RegisterConfig(new SimpleTypedConfig<bool>(
236236
ConfigKeys.DisplaySecretsWarning,
237237
Resources.HelpMessageOfDisplaySecretsWarning,
238-
false,
238+
true,
239239
"AZURE_CLIENTS_SHOW_SECRETS_WARNING",
240240
new[] { AppliesTo.Az }));
241241
configManager.RegisterConfig(new DisableInstanceDiscoveryConfig());

src/Accounts/Authentication/Sanitizer/Providers/SanitizerCollectionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void SanitizeValue(object sanitizingObject, Stack<object> saniti
5151
}
5252
else
5353
{
54-
if (!collItemType.IsValueType && !sanitizingStack.Contains(collItem) && !ExceedsMaxDepth(property, telemetry))
54+
if (!collItemType.IsValueType && !sanitizingStack.Contains(collItem))
5555
{
5656
var provider = resolver.ResolveProvider(collItem.GetType());
5757
provider?.SanitizeValue(collItem, sanitizingStack, resolver, property, telemetry);

src/Accounts/Authentication/Sanitizer/Providers/SanitizerCustomObjectProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void SanitizeValue(object sanitizingObject, Stack<object> saniti
4747
}
4848
else
4949
{
50-
if (!propValueType.IsValueType && !sanitizingStack.Contains(propValue) && !ExceedsMaxDepth(prop, telemetry))
50+
if (!propValueType.IsValueType && !sanitizingStack.Contains(propValue) && ShouldProcessProperty(prop, telemetry))
5151
{
5252
provider.SanitizeValue(propValue, sanitizingStack, resolver, prop, telemetry);
5353
}

src/Accounts/Authentication/Sanitizer/Providers/SanitizerDictionaryProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override void SanitizeValue(object sanitizingObject, Stack<object> saniti
5353
}
5454
else
5555
{
56-
if (!dicItemValueType.IsValueType && !sanitizingStack.Contains(dictItemValue) && !ExceedsMaxDepth(property, telemetry))
56+
if (!dicItemValueType.IsValueType && !sanitizingStack.Contains(dictItemValue))
5757
{
5858
var provider = resolver.ResolveProvider(dicItemValueType);
5959
provider?.SanitizeValue(dictItemValue, sanitizingStack, resolver, property, telemetry);

src/Accounts/Authentication/Sanitizer/Providers/SanitizerProviderBase.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
17-
using Microsoft.ApplicationInsights.Channel;
1815
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services;
1916
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
17+
using System;
18+
using System.Collections.Generic;
2019

2120
namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Providers
2221
{
@@ -46,25 +45,30 @@ protected string ResolvePropertyPath(SanitizerProperty property)
4645
return propertyPath;
4746
}
4847

49-
protected bool ExceedsMaxDepth(SanitizerProperty property, SanitizerTelemetry telemetry)
48+
protected bool ShouldProcessProperty(SanitizerProperty property, SanitizerTelemetry telemetry)
5049
{
5150
if (property == null)
5251
return false;
5352

5453
var currentProperty = property;
54+
var parentProperty = currentProperty.ParentProperty;
5555

5656
for (var i = 0; i < MaxDepth; i++)
5757
{
58-
if (currentProperty.ParentProperty == null)
58+
if (parentProperty == null)
59+
return true;
60+
61+
if (ReferenceEquals(property, parentProperty))
5962
return false;
6063

61-
currentProperty = currentProperty.ParentProperty;
64+
currentProperty = parentProperty;
65+
parentProperty = currentProperty.ParentProperty;
6266
}
6367

6468
telemetry.HasErrorInDetection = true;
65-
telemetry.DetectionError = new Exception($"Potential stack overflow exception may occurr on property: {property.PropertyName}!");
69+
telemetry.DetectionError = new Exception($"Potential stack overflow exception may occurr on property: '{property.PropertyName}' declared in the object '{property.ValueSupplier.DeclaringType.FullName}' with type '{property.PropertyType.FullName}'");
6670

67-
return true;
71+
return false;
6872
}
6973

7074
internal abstract SanitizerProviderType ProviderType { get; }

src/Accounts/Authentication/Sanitizer/Services/DefaultSanitizerService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ internal class DefaultSanitizerService : ISanitizerService
3535
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare", new[] { "ShareProperties" } },
3636
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory", new[] { "ShareDirectoryProperties" } },
3737

38-
// Skip infinite recursion properties
39-
{ "Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.InnerError", new[] { "EmbeddedInnerError" } },
38+
// Skip infinite recursion properties that cause performance concern
39+
40+
// Storage
41+
{ "Microsoft.Azure.Storage.Blob.CloudBlobDirectory", new[] { "Parent" } },
42+
{ "Microsoft.Azure.Storage.File.CloudFileDirectory", new[] { "Parent" } },
4043
};
4144

4245
private static readonly IEnumerable<string> SensitiveDataPatterns = new List<string>()

0 commit comments

Comments
 (0)