Skip to content

Commit 7029300

Browse files
authored
Add telemetry to detect potential infinite recursion properties (#24709)
1 parent f5d92a4 commit 7029300

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

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))
54+
if (!collItemType.IsValueType && !sanitizingStack.Contains(collItem) && !ExceedsMaxDepth(property, telemetry))
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))
50+
if (!propValueType.IsValueType && !sanitizingStack.Contains(propValue) && !ExceedsMaxDepth(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))
56+
if (!dicItemValueType.IsValueType && !sanitizingStack.Contains(dictItemValue) && !ExceedsMaxDepth(property, telemetry))
5757
{
5858
var provider = resolver.ResolveProvider(dicItemValueType);
5959
provider?.SanitizeValue(dictItemValue, sanitizingStack, resolver, property, telemetry);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using System.Collections.Generic;
17+
using Microsoft.ApplicationInsights.Channel;
1618
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services;
1719
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
1820

@@ -44,7 +46,7 @@ protected string ResolvePropertyPath(SanitizerProperty property)
4446
return propertyPath;
4547
}
4648

47-
protected bool ExceedsMaxDepth(SanitizerProperty property)
49+
protected bool ExceedsMaxDepth(SanitizerProperty property, SanitizerTelemetry telemetry)
4850
{
4951
if (property == null)
5052
return false;
@@ -59,6 +61,9 @@ protected bool ExceedsMaxDepth(SanitizerProperty property)
5961
currentProperty = currentProperty.ParentProperty;
6062
}
6163

64+
telemetry.HasErrorInDetection = true;
65+
telemetry.DetectionError = new Exception($"Potential stack overflow exception may occurr on property: {property.PropertyName}!");
66+
6267
return true;
6368
}
6469

0 commit comments

Comments
 (0)