diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs
new file mode 100644
index 000000000000..9f2ad3a0c2fe
--- /dev/null
+++ b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs
@@ -0,0 +1,211 @@
+//
+// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
+// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
+//
+
+#nullable enable
+using System.Collections.Immutable;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.CodeAnalysis.Diagnostics;
+
+namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
+
+///
+/// An analyzer that analyzers aspects that use [AspectMethodInsertAfter] and [AspectMethodInsertBefore]
+/// for example, and checks that they are all wrapped in a try-catch block. These methods should never throw
+/// so they should always have a try-catch block around them.
+///
+[DiagnosticAnalyzer(LanguageNames.CSharp)]
+public class ReplaceAspectAnalyzer : DiagnosticAnalyzer
+{
+ ///
+ /// The diagnostic ID displayed in error messages
+ ///
+ public const string DiagnosticId = "DD0005";
+
+ ///
+ /// The severity of the diagnostic
+ ///
+ public const DiagnosticSeverity Severity = DiagnosticSeverity.Error;
+
+#pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project
+ private static readonly DiagnosticDescriptor MissingTryCatchRule = new(
+ DiagnosticId,
+ title: "Aspect is in incorrect format",
+ messageFormat: "Aspect method bodies should contain a single expression to set the result variable, and then have a try-catch block, and then return the created variable",
+ category: "Reliability",
+ defaultSeverity: Severity,
+ isEnabledByDefault: true,
+ description: "[AspectCtorReplace] and [AspectMethodReplace] Aspects should guarantee safety if possible. Please execute the target method first, then wrap the remainder of the aspect in a try-catch block, and finally return the variable.");
+#pragma warning restore RS2008
+
+ ///
+ public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(MissingTryCatchRule);
+
+ ///
+ public override void Initialize(AnalysisContext context)
+ {
+ context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
+ context.EnableConcurrentExecution();
+
+ // Consider registering other actions that act on syntax instead of or in addition to symbols
+ // See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Analyzer%20Actions%20Semantics.md for more information
+ context.RegisterSyntaxNodeAction(AnalyseMethod, SyntaxKind.MethodDeclaration);
+ }
+
+ private void AnalyseMethod(SyntaxNodeAnalysisContext context)
+ {
+ // assume that generated code is safe, so bail out for perf reasons
+ if (context.IsGeneratedCode || context.Node is not MethodDeclarationSyntax methodDeclaration)
+ {
+ return;
+ }
+
+ var attributes = methodDeclaration.AttributeLists;
+ if (!attributes.Any())
+ {
+ // no attributes, let's just bail
+ return;
+ }
+
+ var hasAspectAttribute = false;
+ foreach (var attributeList in attributes)
+ {
+ foreach (var attribute in attributeList.Attributes)
+ {
+ var name = attribute.Name.ToString();
+ if (name is "AspectCtorReplace" or "AspectMethodReplace"
+ or "AspectCtorReplaceAttribute" or "AspectMethodReplaceAttribute")
+ {
+ hasAspectAttribute = true;
+ break;
+ }
+ }
+ }
+
+ if (!hasAspectAttribute)
+ {
+ // not an aspect
+ return;
+ }
+
+ var bodyBlock = methodDeclaration.Body;
+ var isVoidMethod = methodDeclaration.ReturnType is PredefinedTypeSyntax { Keyword.Text: "void" };
+ int expectedStatements = isVoidMethod ? 2 : 3;
+
+ if (bodyBlock is null)
+ {
+ // If we don't have a bodyBlock, it's probably a lambda or expression bodied member
+ // These can't have try catch blocks, so we should bail out
+ var location = methodDeclaration.ExpressionBody?.GetLocation() ?? methodDeclaration.GetLocation();
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, location));
+ return;
+ }
+
+ if (!bodyBlock.Statements.Any())
+ {
+ // ignore this case, for now, if there's nothing in there, it's safe, and we don't want to hassle users too soon
+ return;
+ }
+
+ if (bodyBlock.Statements.Count != expectedStatements)
+ {
+ // We require exactly a predefined amount of statements, so this must be an error
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ return;
+ }
+
+ // check the first statement
+ if (!isVoidMethod && bodyBlock.Statements[0] is not LocalDeclarationStatementSyntax)
+ {
+ // this is an error, and we can't go much further
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ return;
+ }
+
+ if (bodyBlock.Statements[1] is not TryStatementSyntax tryCatchStatement)
+ {
+ // oops, you should have a try block here
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ return;
+ }
+
+ CatchClauseSyntax? catchClause = null;
+ var hasFilter = false;
+ var isSystemException = false;
+ var isRethrowing = false;
+
+ foreach (var catchSyntax in tryCatchStatement.Catches)
+ {
+ catchClause = catchSyntax;
+ isSystemException = false;
+ isRethrowing = false;
+
+ // check that it's catching _everything_
+ hasFilter = catchClause.Filter is not null;
+ if (hasFilter)
+ {
+ // Skipping because we shouldn't be letting anything through
+ continue;
+ }
+
+ var exceptionTypeName = catchSyntax.Declaration?.Type is { } exceptionType
+ ? context.SemanticModel.GetSymbolInfo(exceptionType).Symbol?.ToString()
+ : null;
+ isSystemException = exceptionTypeName is null or "System.Exception";
+ if (!isSystemException)
+ {
+ // skipping because it's not broad enough
+ continue;
+ }
+
+ // final requirement, must not be rethrowing
+ foreach (var statement in catchSyntax.Block.Statements)
+ {
+ if (statement is ThrowStatementSyntax)
+ {
+ isRethrowing = true;
+ break;
+ }
+ }
+
+ // if we get here, we know one of the loops is all good, so we can break
+ break;
+ }
+
+ if (catchClause is null || hasFilter || !isSystemException || isRethrowing)
+ {
+ // oops, no good
+ var location = catchClause?.GetLocation() ?? tryCatchStatement.GetLocation();
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, location));
+ }
+
+ // final check, do we return the variable?
+ if (!isVoidMethod)
+ {
+ if (bodyBlock.Statements[2] is not ReturnStatementSyntax returnStatement)
+ {
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ return;
+ }
+
+ // should be returning the variable
+ if (returnStatement.Expression is not IdentifierNameSyntax identifierName)
+ {
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ return;
+ }
+
+ LocalDeclarationStatementSyntax localDeclaration = (LocalDeclarationStatementSyntax)bodyBlock.Statements[0];
+ if (!localDeclaration.Declaration.Variables.Any()
+ || localDeclaration.Declaration.Variables[0] is not { } variable
+ || variable.Identifier.ToString() != identifierName.Identifier.ToString())
+ {
+ // not returning the right thing
+ context.ReportDiagnostic(Diagnostic.Create(MissingTryCatchRule, bodyBlock.GetLocation()));
+ }
+ }
+ }
+}
diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs
new file mode 100644
index 000000000000..ea5be4493f7c
--- /dev/null
+++ b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs
@@ -0,0 +1,126 @@
+//
+// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
+// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
+//
+
+#nullable enable
+using System.Collections.Immutable;
+using System.Composition;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CodeActions;
+using Microsoft.CodeAnalysis.CodeFixes;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.CodeAnalysis.Formatting;
+
+namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
+
+///
+/// A CodeFixProvider for the
+///
+[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ReplaceAspectCodeFixProvider))]
+[Shared]
+public class ReplaceAspectCodeFixProvider : CodeFixProvider
+{
+ ///
+ public sealed override ImmutableArray FixableDiagnosticIds
+ {
+ get => ImmutableArray.Create(ReplaceAspectAnalyzer.DiagnosticId);
+ }
+
+ ///
+ public sealed override FixAllProvider GetFixAllProvider()
+ {
+ // See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers
+ return WellKnownFixAllProviders.BatchFixer;
+ }
+
+ ///
+ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
+ {
+ var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
+
+ var diagnostic = context.Diagnostics.First();
+ var diagnosticSpan = diagnostic.Location.SourceSpan;
+
+ // Find the methodDeclaration identified by the diagnostic.
+ var methodDeclaration = root?.FindToken(diagnosticSpan.Start)
+ .Parent
+ ?.AncestorsAndSelf()
+ .OfType()
+ .First();
+
+ if (methodDeclaration?.Body is { Statements.Count: >2 } body
+ && body.Statements[0] is LocalDeclarationStatementSyntax localDeclaration
+ && body.Statements[body.Statements.Count - 1] is ReturnStatementSyntax { Expression: IdentifierNameSyntax identifierName }
+ && localDeclaration.Declaration.Variables.Count == 1
+ && localDeclaration.Declaration.Variables[0] is { } variable
+ && variable.Identifier.ToString() == identifierName.Identifier.ToString())
+ {
+ // Register a code action that will invoke the fix.
+ context.RegisterCodeFix(
+ CodeAction.Create(
+ title: "Wrap internals with exception handler",
+ createChangedDocument: c => AddTryCatch(context.Document, methodDeclaration, c),
+ equivalenceKey: nameof(ReplaceAspectCodeFixProvider)),
+ diagnostic);
+ }
+ }
+
+ private async Task AddTryCatch(Document document, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
+ {
+ // we know we're calling this with something we can fix,
+ // we just need to work out if we need to wrap the internals in a try-catch
+ // or add a catch statement
+ var body = methodDeclaration.Body!;
+ var localDeclaration = (LocalDeclarationStatementSyntax)body.Statements[0];
+ var returnSyntax = (ReturnStatementSyntax)body.Statements[body.Statements.Count - 1];
+ TryStatementSyntax tryCatch;
+
+ if (body.Statements.Count == 3 && body.Statements[1] is TryStatementSyntax tryStatementSyntax)
+ {
+ tryCatch = tryStatementSyntax;
+ }
+ else
+ {
+ var block = SyntaxFactory.Block(body.Statements.Skip(1).Take(body.Statements.Count - 2));
+ tryCatch = SyntaxFactory.TryStatement().WithBlock(block);
+ }
+
+ // Add the catch statement to the try-catch block
+ var parentType = methodDeclaration.AncestorsAndSelf()
+ .FirstOrDefault(x => x is TypeDeclarationSyntax or RecordDeclarationSyntax or StructDeclarationSyntax);
+ var typeName = parentType switch
+ {
+ StructDeclarationSyntax t => t.Identifier.Text,
+ RecordDeclarationSyntax t => t.Identifier.Text,
+ TypeDeclarationSyntax t => t.Identifier.Text,
+ _ => "UNKNOWN",
+ };
+
+ var methodName = methodDeclaration.Identifier.Text;
+
+ var catchDeclaration = SyntaxFactory.CatchDeclaration(SyntaxFactory.IdentifierName("Exception"), SyntaxFactory.Identifier("ex"));
+ var logExpression = SyntaxFactory.ExpressionStatement(
+ SyntaxFactory.ParseExpression($$"""IastModule.Log.Error(ex, $"Error invoking {nameof({{typeName}})}.{nameof({{methodName}})}")"""));
+
+ var catchSyntax = SyntaxFactory.CatchClause()
+ .WithDeclaration(catchDeclaration)
+ .WithBlock(SyntaxFactory.Block(logExpression));
+
+ var updatedTryCatch = tryCatch.AddCatches(catchSyntax);
+ var newBody = SyntaxFactory.Block(localDeclaration, updatedTryCatch, returnSyntax)
+ .WithAdditionalAnnotations(Formatter.Annotation);
+
+ var newMethodDeclaration = methodDeclaration.WithBody(newBody);
+
+ // replace the syntax and return updated document
+ var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
+ root = root!.ReplaceNode(methodDeclaration, newMethodDeclaration);
+ return document.WithSyntaxRoot(root);
+ }
+}
diff --git a/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
index 1041a3f633ca..5e1e1e8f9784 100644
--- a/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
+++ b/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
@@ -422,8 +422,7 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Concat(System.Object,System.Object,System.Object,System.Object)\",\"\",[0],[False],[None],Default,[])] Concat(System.Object,System.Object,System.Object,System.Object)",
" [AspectMethodReplace(\"System.String::Concat(System.String[])\",\"\",[0],[False],[None],Default,[])] Concat(System.String[])",
" [AspectMethodReplace(\"System.String::Concat(System.Object[])\",\"\",[0],[False],[None],Default,[])] Concat(System.Object[])",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat2(System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::ToCharArray()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToCharArray(System.String)",
@@ -431,8 +430,7 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[],System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::Join(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[])",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::ToUpper()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String)",
" [AspectMethodReplace(\"System.String::ToUpper(System.Globalization.CultureInfo)\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String,System.Globalization.CultureInfo)",
" [AspectMethodReplace(\"System.String::ToUpperInvariant()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpperInvariant(System.String)",
diff --git a/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
index a218dc456b99..a4588db8d23f 100644
--- a/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
+++ b/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
@@ -460,8 +460,7 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Concat(System.String,System.String,System.String,System.String)\",\"\",[0],[False],[StringLiterals],Default,[])] Concat(System.String,System.String,System.String,System.String)",
" [AspectMethodReplace(\"System.String::Concat(System.String[])\",\"\",[0],[False],[None],Default,[])] Concat(System.String[])",
" [AspectMethodReplace(\"System.String::Concat(System.Object[])\",\"\",[0],[False],[None],Default,[])] Concat(System.Object[])",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat2(System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::ToCharArray()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToCharArray(System.String)",
@@ -470,11 +469,9 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[])",
" [AspectMethodReplace(\"System.String::Join(System.Char,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[],System.Int32,System.Int32)",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Collections.IEnumerable)",
" [AspectMethodReplace(\"System.String::Join(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[])",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::ToUpper()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String)",
" [AspectMethodReplace(\"System.String::ToUpper(System.Globalization.CultureInfo)\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String,System.Globalization.CultureInfo)",
" [AspectMethodReplace(\"System.String::ToUpperInvariant()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpperInvariant(System.String)",
@@ -562,8 +559,6 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.String,System.Object[])",
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.String[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.String[])",
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.Object[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.Object[])",
-" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.Object)",
-" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.String,System.Object)",
"[AspectClass(\"mscorlib,netstandard,System.Runtime\",[None],Sink,[ReflectionInjection])] Datadog.Trace.Iast.Aspects.ActivatorAspect",
" [AspectMethodInsertBefore(\"System.Activator::CreateInstance(System.String,System.String)\",\"\",[1,0],[False,False],[None],Default,[])] ReflectionInjectionParam(System.String)",
" [AspectMethodInsertBefore(\"System.Activator::CreateInstance(System.String,System.String,System.Object[])\",\"\",[2,1],[False,False],[None],Default,[])] ReflectionInjectionParam(System.String)",
diff --git a/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
index 4a80425b467f..bde765f70c44 100644
--- a/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
+++ b/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
@@ -447,8 +447,7 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Concat(System.String,System.String,System.String,System.String)\",\"\",[0],[False],[StringLiterals],Default,[])] Concat(System.String,System.String,System.String,System.String)",
" [AspectMethodReplace(\"System.String::Concat(System.String[])\",\"\",[0],[False],[None],Default,[])] Concat(System.String[])",
" [AspectMethodReplace(\"System.String::Concat(System.Object[])\",\"\",[0],[False],[None],Default,[])] Concat(System.Object[])",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat2(System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::ToCharArray()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToCharArray(System.String)",
@@ -457,11 +456,9 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[])",
" [AspectMethodReplace(\"System.String::Join(System.Char,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[],System.Int32,System.Int32)",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Collections.IEnumerable)",
" [AspectMethodReplace(\"System.String::Join(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[])",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::ToUpper()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String)",
" [AspectMethodReplace(\"System.String::ToUpper(System.Globalization.CultureInfo)\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String,System.Globalization.CultureInfo)",
" [AspectMethodReplace(\"System.String::ToUpperInvariant()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpperInvariant(System.String)",
@@ -549,8 +546,6 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.String,System.Object[])",
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.String[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.String[])",
" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.Object[])\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.Object[])",
-" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.Char,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.Char,System.Object)",
-" [AspectMethodReplace(\"System.Text.StringBuilder::AppendJoin(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] AppendJoin(System.Text.StringBuilder,System.String,System.Object)",
"[AspectClass(\"mscorlib,netstandard,System.Runtime\",[None],Sink,[ReflectionInjection])] Datadog.Trace.Iast.Aspects.ActivatorAspect",
" [AspectMethodInsertBefore(\"System.Activator::CreateInstance(System.String,System.String)\",\"\",[1,0],[False,False],[None],Default,[])] ReflectionInjectionParam(System.String)",
" [AspectMethodInsertBefore(\"System.Activator::CreateInstance(System.String,System.String,System.Object[])\",\"\",[2,1],[False,False],[None],Default,[])] ReflectionInjectionParam(System.String)",
diff --git a/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
index b78d5a119485..eff6b126162c 100644
--- a/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
+++ b/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/AspectsDefinitionsGenerator/AspectsDefinitions.g.cs
@@ -433,21 +433,15 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Concat(System.String,System.String,System.String,System.String)\",\"\",[0],[False],[StringLiterals],Default,[])] Concat(System.String,System.String,System.String,System.String)",
" [AspectMethodReplace(\"System.String::Concat(System.String[])\",\"\",[0],[False],[None],Default,[])] Concat(System.String[])",
" [AspectMethodReplace(\"System.String::Concat(System.Object[])\",\"\",[0],[False],[None],Default,[])] Concat(System.Object[])",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat2(System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Concat(System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32)",
" [AspectMethodReplace(\"System.String::Substring(System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Substring(System.String,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::ToCharArray()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToCharArray(System.String)",
" [AspectMethodReplace(\"System.String::ToCharArray(System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToCharArray(System.String,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[],System.Int32,System.Int32)",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[])",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Object[])",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.String[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.String[],System.Int32,System.Int32)",
-" [AspectMethodReplace(\"System.String::Join(System.Char,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.Char,System.Collections.IEnumerable)",
" [AspectMethodReplace(\"System.String::Join(System.String,System.Object[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Object[])",
" [AspectMethodReplace(\"System.String::Join(System.String,System.String[])\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.String[])",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.IEnumerable)",
-" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] Join(System.String,System.Collections.IEnumerable)",
+" [AspectMethodReplace(\"System.String::Join(System.String,System.Collections.Generic.IEnumerable`1)\",\"\",[0],[False],[None],Default,[])] JoinString(System.String,System.Collections.Generic.IEnumerable)",
" [AspectMethodReplace(\"System.String::ToUpper()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String)",
" [AspectMethodReplace(\"System.String::ToUpper(System.Globalization.CultureInfo)\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpper(System.String,System.Globalization.CultureInfo)",
" [AspectMethodReplace(\"System.String::ToUpperInvariant()\",\"\",[0],[False],[StringLiteral_0],Default,[])] ToUpperInvariant(System.String)",
@@ -477,10 +471,6 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.String::Split(System.Char[],System.Int32,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.Char[],System.Int32,System.StringSplitOptions)",
" [AspectMethodReplace(\"System.String::Split(System.String[],System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.String[],System.StringSplitOptions)",
" [AspectMethodReplace(\"System.String::Split(System.String[],System.Int32,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.String[],System.Int32,System.StringSplitOptions)",
-" [AspectMethodReplace(\"System.String::Split(System.String,System.Int32,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.String,System.Int32,System.StringSplitOptions)",
-" [AspectMethodReplace(\"System.String::Split(System.String,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.String,System.StringSplitOptions)",
-" [AspectMethodReplace(\"System.String::Split(System.Char,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.Char,System.StringSplitOptions)",
-" [AspectMethodReplace(\"System.String::Split(System.Char,System.Int32,System.StringSplitOptions)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Split(System.String,System.Char,System.Int32,System.StringSplitOptions)",
" [AspectMethodReplace(\"System.String::Copy(System.String)\",\"\",[0],[False],[StringLiteral_0],Default,[])] Copy(System.String)",
"[AspectClass(\"mscorlib,netstandard,System.Runtime\",[None],Propagation,[])] Datadog.Trace.Iast.Aspects.System.Text.StringBuilderAspects",
" [AspectCtorReplace(\"System.Text.StringBuilder::.ctor(System.String)\",\"\",[0],[False],[StringLiteral_1],Default,[])] Init(System.String)",
@@ -491,7 +481,6 @@ internal static partial class AspectDefinitions
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.String)\",\"\",[0],[False],[StringLiteral_1],Default,[])] Append(System.Text.StringBuilder,System.String)",
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.Text.StringBuilder)\",\"\",[0],[False],[None],Default,[])] Append(System.Text.StringBuilder,System.Text.StringBuilder)",
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.String,System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_1],Default,[])] Append(System.Text.StringBuilder,System.String,System.Int32,System.Int32)",
-" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.Text.StringBuilder,System.Int32,System.Int32)\",\"\",[0],[False],[StringLiteral_1],Default,[])] Append(System.Text.StringBuilder,System.Text.StringBuilder,System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.Char[],System.Int32,System.Int32)\",\"\",[0],[False],[None],Default,[])] Append(System.Text.StringBuilder,System.Char[],System.Int32,System.Int32)",
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.Object)\",\"\",[0],[False],[None],Default,[])] Append(System.Text.StringBuilder,System.Object)",
" [AspectMethodReplace(\"System.Text.StringBuilder::Append(System.Char[])\",\"\",[0],[False],[None],Default,[])] Append(System.Text.StringBuilder,System.Char[])",
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Net/WebUtilityAspect.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Net/WebUtilityAspect.cs
index f88d2e0025d2..b3dbe86d0619 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Net/WebUtilityAspect.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Net/WebUtilityAspect.cs
@@ -26,6 +26,19 @@ public class WebUtilityAspect
[AspectMethodReplace("System.Net.WebUtility::HtmlEncode(System.String)")]
public static string? Review(string? parameter)
{
- return IastModule.OnXssEscape(parameter);
+ var result = WebUtility.HtmlEncode(parameter);
+ try
+ {
+ if (parameter is not null && result is not null)
+ {
+ return IastModule.OnXssEscape(parameter, result);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(WebUtilityAspect)}.{nameof(Review)}");
+ }
+
+ return result;
}
}
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Security.Cryptography/SymmetricAlgorithmAspect.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Security.Cryptography/SymmetricAlgorithmAspect.cs
index 0971bda04518..a6296465fa6a 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Security.Cryptography/SymmetricAlgorithmAspect.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Security.Cryptography/SymmetricAlgorithmAspect.cs
@@ -44,7 +44,15 @@ private static void ProcessCipherClassCreation(SymmetricAlgorithm target)
public static DESCryptoServiceProvider InitDES()
{
var target = new DESCryptoServiceProvider();
- ProcessCipherClassCreation(target);
+ try
+ {
+ ProcessCipherClassCreation(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(SymmetricAlgorithmAspect)}.{nameof(InitDES)}");
+ }
+
return target;
}
@@ -56,7 +64,15 @@ public static DESCryptoServiceProvider InitDES()
public static RC2CryptoServiceProvider InitRC2()
{
var target = new RC2CryptoServiceProvider();
- ProcessCipherClassCreation(target);
+ try
+ {
+ ProcessCipherClassCreation(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(SymmetricAlgorithmAspect)}.{nameof(InitRC2)}");
+ }
+
return target;
}
@@ -68,7 +84,15 @@ public static RC2CryptoServiceProvider InitRC2()
public static TripleDESCryptoServiceProvider InitTripleDES()
{
var target = new TripleDESCryptoServiceProvider();
- ProcessCipherClassCreation(target);
+ try
+ {
+ ProcessCipherClassCreation(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(SymmetricAlgorithmAspect)}.{nameof(InitTripleDES)}");
+ }
+
return target;
}
@@ -80,7 +104,15 @@ public static TripleDESCryptoServiceProvider InitTripleDES()
public static RijndaelManaged InitRijndaelManaged()
{
var target = new RijndaelManaged();
- ProcessCipherClassCreation(target);
+ try
+ {
+ ProcessCipherClassCreation(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(SymmetricAlgorithmAspect)}.{nameof(InitRijndaelManaged)}");
+ }
+
return target;
}
@@ -92,7 +124,15 @@ public static RijndaelManaged InitRijndaelManaged()
public static AesCryptoServiceProvider InitAesCryptoServiceProvider()
{
var target = new AesCryptoServiceProvider();
- ProcessCipherClassCreation(target);
+ try
+ {
+ ProcessCipherClassCreation(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(SymmetricAlgorithmAspect)}.{nameof(InitAesCryptoServiceProvider)}");
+ }
+
return target;
}
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Text.Json/JsonDocumentAspects.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Text.Json/JsonDocumentAspects.cs
index 1d78e90ec24a..74f390f0b1e3 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Text.Json/JsonDocumentAspects.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Text.Json/JsonDocumentAspects.cs
@@ -54,6 +54,7 @@ public static object Parse(string json, JsonDocumentOptions options)
/// the string result
[AspectMethodReplace("System.Text.Json.JsonElement::GetString()", [0], [true])]
public static string? GetString(object target)
+#pragma warning disable DD0005 // Function is already safe where needed
{
IJsonElement? element;
try
@@ -84,6 +85,7 @@ public static object Parse(string json, JsonDocumentOptions options)
return str;
}
+#pragma warning restore DD0005
///
/// GetRawText method aspect
@@ -93,6 +95,7 @@ public static object Parse(string json, JsonDocumentOptions options)
/// the raw string result
[AspectMethodReplace("System.Text.Json.JsonElement::GetRawText()", [0], [true])]
public static string? GetRawText(object target)
+#pragma warning disable DD0005 // Function is already safe where needed
{
IJsonElement? element;
try
@@ -123,6 +126,7 @@ public static object Parse(string json, JsonDocumentOptions options)
return str;
}
+#pragma warning restore DD0005
private static void TaintJsonElements(string json, JsonDocument doc)
{
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Text/StringBuilderAspects.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Text/StringBuilderAspects.cs
index 1068f3535e7c..55c43d151d72 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Text/StringBuilderAspects.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Text/StringBuilderAspects.cs
@@ -30,7 +30,15 @@ public class StringBuilderAspects
public static StringBuilder Init(string? value)
{
var result = new StringBuilder(value);
- PropagationModuleImpl.PropagateTaint(value, result);
+ try
+ {
+ PropagationModuleImpl.PropagateTaint(value, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Init)}");
+ }
+
return result;
}
@@ -42,7 +50,15 @@ public static StringBuilder Init(string? value)
public static StringBuilder Init(string? value, int capacity)
{
var result = new StringBuilder(value, capacity);
- PropagationModuleImpl.PropagateTaint(value, result);
+ try
+ {
+ PropagationModuleImpl.PropagateTaint(value, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Init)}");
+ }
+
return result;
}
@@ -56,7 +72,15 @@ public static StringBuilder Init(string? value, int capacity)
public static StringBuilder Init(string? value, int startIndex, int length, int capacity)
{
var result = new StringBuilder(value, startIndex, length, capacity);
- StringBuilderModuleImpl.OnStringBuilderSubSequence(value, startIndex, length, result);
+ try
+ {
+ StringBuilderModuleImpl.OnStringBuilderSubSequence(value, startIndex, length, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Init)}");
+ }
+
return result;
}
@@ -66,13 +90,18 @@ public static StringBuilder Init(string? value, int startIndex, int length, int
[AspectMethodReplace("System.Object::ToString()", "System.Text.StringBuilder")]
public static string? ToString(object? target)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.ToString();
-
- if (target is StringBuilder)
+ try
{
- PropagationModuleImpl.PropagateTaint(target, result);
- PropagationModuleImpl.FixRangesIfNeeded(result);
+ if (target is StringBuilder)
+ {
+ PropagationModuleImpl.PropagateTaint(target, result);
+ PropagationModuleImpl.FixRangesIfNeeded(result);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(ToString)}");
}
return result;
@@ -86,10 +115,17 @@ public static StringBuilder Init(string? value, int startIndex, int length, int
[AspectMethodReplace("System.Text.StringBuilder::ToString(System.Int32,System.Int32)")]
public static string ToString(StringBuilder? target, int startIndex, int length)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.ToString(startIndex, length);
- PropagationModuleImpl.OnStringSubSequence(target, startIndex, result, result.Length);
- PropagationModuleImpl.FixRangesIfNeeded(result);
+ try
+ {
+ PropagationModuleImpl.OnStringSubSequence(target, startIndex, result, result.Length);
+ PropagationModuleImpl.FixRangesIfNeeded(result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(ToString)}");
+ }
+
return result;
}
@@ -100,11 +136,22 @@ public static string ToString(StringBuilder? target, int startIndex, int length)
[AspectMethodReplace("System.Text.StringBuilder::Append(System.String)", AspectFilter.StringLiteral_1)]
public static StringBuilder Append(StringBuilder? target, string? value)
{
- var initialLength = target?.Length ?? 0;
- var length = value?.Length ?? 0;
- // We want the null reference exception to be launched here if target is null
var result = target!.Append(value);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var length = value.Length;
+ var initialLength = target.Length - length;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
#if !NETFRAMEWORK
@@ -115,11 +162,22 @@ public static StringBuilder Append(StringBuilder? target, string? value)
[AspectMethodReplace("System.Text.StringBuilder::Append(System.Text.StringBuilder)")]
public static StringBuilder Append(StringBuilder? target, StringBuilder? value)
{
- var initialLength = target?.Length ?? 0;
- var length = value?.Length ?? 0;
- // We want the null reference exception to be launched here if target is null
var result = target!.Append(value);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var length = value.Length;
+ var initialLength = target.Length - length;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
#endif
@@ -132,13 +190,24 @@ public static StringBuilder Append(StringBuilder? target, StringBuilder? value)
[AspectMethodReplace("System.Text.StringBuilder::Append(System.String,System.Int32,System.Int32)", AspectFilter.StringLiteral_1)]
public static StringBuilder Append(StringBuilder? target, string? value, int startIndex, int count)
{
- var initialLength = target?.Length ?? 0;
- // We want the null reference exception to be launched here if target is null
var result = target!.Append(value, startIndex, count);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value?.Length ?? 0, startIndex, count);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var initialLength = target.Length - count;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value.Length, startIndex, count);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
-#if !NETFRAMEWORK
+#if NETCOREAPP
/// StringBuilder.Append aspect
/// StringBuilder instance
/// string parameter
@@ -148,32 +217,48 @@ public static StringBuilder Append(StringBuilder? target, string? value, int sta
[AspectMethodReplace("System.Text.StringBuilder::Append(System.Text.StringBuilder,System.Int32,System.Int32)", AspectFilter.StringLiteral_1)]
public static StringBuilder Append(StringBuilder? target, StringBuilder? value, int startIndex, int count)
{
- var initialLength = target?.Length ?? 0;
- // We want the null reference exception to be launched here if target is null
- // netcore2.1 defines this overload, but not netstandard, so we have to call ToString()
-#if NETSTANDARD
- var result = target!.Append(value?.ToString(), startIndex, count);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value?.Length ?? 0, startIndex, count);
-#else
var result = target!.Append(value, startIndex, count);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value?.Length ?? 0, startIndex, count);
-#endif
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var initialLength = target.Length - count;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value.Length, startIndex, count);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
#endif
- /// StringBuilder.Append aspect
- /// StringBuilder instance
- /// string parameter
- /// startIndex parameter
- /// charCount parameter
- /// instance.Append()
+ /// StringBuilder.Append aspect
+ /// StringBuilder instance
+ /// string parameter
+ /// startIndex parameter
+ /// charCount parameter
+ /// instance.Append()
[AspectMethodReplace("System.Text.StringBuilder::Append(System.Char[],System.Int32,System.Int32)")]
public static StringBuilder Append(StringBuilder? target, char[]? value, int startIndex, int charCount)
{
- var initialLength = target?.Length ?? 0;
- // We want the null reference exception to be launched here if target is null
var result = target!.Append(value, startIndex, charCount);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value?.Length ?? 0, startIndex, charCount);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var initialLength = target.Length - charCount;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, value.Length, startIndex, charCount);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
/// StringBuilder.Append aspect
@@ -183,24 +268,34 @@ public static StringBuilder Append(StringBuilder? target, char[]? value, int sta
[AspectMethodReplace("System.Text.StringBuilder::Append(System.Object)")]
public static StringBuilder Append(StringBuilder? target, object? value)
{
- var initialLength = target?.Length ?? 0;
-
- object? valueObject;
- int length;
- if (value is StringBuilder valueStringBuilder)
+ var result = target!.Append(value);
+ try
{
- valueObject = valueStringBuilder;
- length = valueStringBuilder!.Length;
+ if (target is not null && value is not null)
+ {
+ object? valueObject;
+ int length;
+ if (value is StringBuilder valueStringBuilder)
+ {
+ valueObject = valueStringBuilder;
+ length = valueStringBuilder!.Length;
+ }
+ else
+ {
+ valueObject = value?.ToString();
+ length = (valueObject as string)?.Length ?? 0;
+ }
+
+ var initialLength = target.Length - length;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, valueObject, length, 0, length);
+ }
}
- else
+ catch (Exception ex)
{
- valueObject = value?.ToString();
- length = (valueObject as string)?.Length ?? 0;
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
}
- // We want the null reference exception to be launched here if target is null
- var result = target!.Append(value);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, valueObject, length, 0, length);
+ return result;
}
/// StringBuilder.Append aspect
@@ -210,12 +305,22 @@ public static StringBuilder Append(StringBuilder? target, object? value)
[AspectMethodReplace("System.Text.StringBuilder::Append(System.Char[])")]
public static StringBuilder Append(StringBuilder? target, char[]? value)
{
- var initialLength = target?.Length ?? 0;
- var length = value?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Append(value);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var length = value.Length;
+ var initialLength = target.Length - length;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Append)}");
+ }
+
+ return result;
}
/// StringBuilder.AppendLine aspect
@@ -225,12 +330,23 @@ public static StringBuilder Append(StringBuilder? target, char[]? value)
[AspectMethodReplace("System.Text.StringBuilder::AppendLine(System.String)", AspectFilter.StringLiteral_1)]
public static StringBuilder AppendLine(StringBuilder? target, string? value)
{
- var initialLength = target?.Length ?? 0;
- var length = value?.Length ?? 0;
- // We do not take into account the endline char because it is not tainted
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendLine(value);
- return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ try
+ {
+ // We do not take into account the endline char because it is not tainted
+ if (target is not null && value is not null)
+ {
+ var length = value.Length;
+ var initialLength = target.Length - length - Environment.NewLine.Length;
+ return StringBuilderModuleImpl.OnStringBuilderAppend(result, initialLength, value, length, 0, length);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendLine)}");
+ }
+
+ return result;
}
/// StringBuilder.AppendFormat aspect
@@ -241,9 +357,16 @@ public static StringBuilder AppendLine(StringBuilder? target, string? value)
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.String,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, string? format, object? arg0)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(format!, arg0);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -256,9 +379,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, string? format,
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.String,System.Object,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, string? format, object? arg0, object? arg1)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(format!, arg0, arg1);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -272,9 +402,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, string? format,
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.String,System.Object,System.Object,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, string? format, object? arg0, object? arg1, object? arg2)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(format!, arg0, arg1, arg2);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1, arg2);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1, arg2);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -286,9 +423,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, string? format,
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.String,System.Object[])")]
public static StringBuilder AppendFormat(StringBuilder? target, string? format, object[]? args)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(format!, args!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, format, args);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, format, args);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -301,9 +445,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, string? format,
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.IFormatProvider,System.String,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider? provider, string? format, object? arg0)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(provider, format!, arg0);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -317,9 +468,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider?
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.IFormatProvider,System.String,System.Object,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider? provider, string? format, object? arg0, object? arg1)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(provider, format!, arg0, arg1);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -334,9 +492,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider?
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.IFormatProvider,System.String,System.Object,System.Object,System.Object)")]
public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider? provider, string? format, object? arg0, object? arg1, object? arg2)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(provider, format!, arg0, arg1, arg2);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1, arg2);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, format, arg0, arg1, arg2);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -349,9 +514,16 @@ public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider?
[AspectMethodReplace("System.Text.StringBuilder::AppendFormat(System.IFormatProvider,System.String,System.Object[])")]
public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider? provider, string? format, object[]? args)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendFormat(provider, format!, args!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, format, args);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, format, args);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendFormat)}");
+ }
+
return result;
}
@@ -364,9 +536,15 @@ public static StringBuilder AppendFormat(StringBuilder? target, IFormatProvider?
[AspectMethodReplace("System.Text.StringBuilder::CopyTo(System.Int32,System.Char[],System.Int32,System.Int32)")]
public static void CopyTo(StringBuilder? target, int sourceIndex, char[]? destination, int destinationIndex, int count)
{
- // We want the null reference exception to be launched here if target is null
target!.CopyTo(sourceIndex, destination!, destinationIndex, count);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(destination, target);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(destination, target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(CopyTo)}");
+ }
}
/// StringBuilder.Insert aspect
@@ -377,11 +555,20 @@ public static void CopyTo(StringBuilder? target, int sourceIndex, char[]? destin
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.String)")]
public static StringBuilder Insert(StringBuilder? target, int index, string? value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var previousLength = target.Length - value.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -394,11 +581,20 @@ public static StringBuilder Insert(StringBuilder? target, int index, string? val
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.String,System.Int32)")]
public static StringBuilder Insert(StringBuilder? target, int index, string? value, int count)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value, count);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value, count);
+ try
+ {
+ if (target is not null && value is not null && count > 0)
+ {
+ var previousLength = target.Length - (value.Length * count);
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value, count);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -410,11 +606,20 @@ public static StringBuilder Insert(StringBuilder? target, int index, string? val
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Char)")]
public static StringBuilder Insert(StringBuilder? target, int index, char value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var previousLength = target.Length - 1;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -426,11 +631,20 @@ public static StringBuilder Insert(StringBuilder? target, int index, char value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Char[])")]
public static StringBuilder Insert(StringBuilder? target, int index, char[]? value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var previousLength = target.Length - value.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -444,11 +658,20 @@ public static StringBuilder Insert(StringBuilder? target, int index, char[]? val
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Char[],System.Int32,System.Int32)")]
public static StringBuilder Insert(StringBuilder? target, int index, char[]? value, int startIndex, int charCount)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value, startIndex, charCount);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value, 1, startIndex, charCount);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var previousLength = target.Length - charCount;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value, 1, startIndex, charCount);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -460,11 +683,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, char[]? val
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Int32)")]
public static StringBuilder Insert(StringBuilder? target, int index, int value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -476,11 +709,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, int value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Int64)")]
public static StringBuilder Insert(StringBuilder? target, int index, long value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -492,11 +735,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, long value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Single)")]
public static StringBuilder Insert(StringBuilder? target, int index, float value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -508,11 +761,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, float value
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Double)")]
public static StringBuilder Insert(StringBuilder? target, int index, double value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -524,11 +787,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, double valu
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Decimal)")]
public static StringBuilder Insert(StringBuilder? target, int index, decimal value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -540,11 +813,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, decimal val
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.UInt16)")]
public static StringBuilder Insert(StringBuilder? target, int index, ushort value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -556,11 +839,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, ushort valu
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.UInt32)")]
public static StringBuilder Insert(StringBuilder? target, int index, uint value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -572,11 +865,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, uint value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.UInt64)")]
public static StringBuilder Insert(StringBuilder? target, int index, ulong value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -588,11 +891,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, ulong value
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Boolean)")]
public static StringBuilder Insert(StringBuilder? target, int index, bool value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -604,11 +917,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, bool value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.SByte)")]
public static StringBuilder Insert(StringBuilder? target, int index, sbyte value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -620,11 +943,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, sbyte value
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Byte)")]
public static StringBuilder Insert(StringBuilder? target, int index, byte value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -636,11 +969,21 @@ public static StringBuilder Insert(StringBuilder? target, int index, byte value)
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Int16)")]
public static StringBuilder Insert(StringBuilder? target, int index, short value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -650,13 +993,23 @@ public static StringBuilder Insert(StringBuilder? target, int index, short value
/// The object to insert.
/// The modified StringBuilder instance.
[AspectMethodReplace("System.Text.StringBuilder::Insert(System.Int32,System.Object)")]
- public static StringBuilder Insert(StringBuilder? target, int index, object value)
+ public static StringBuilder Insert(StringBuilder? target, int index, object? value)
{
- var previousLength = target?.Length ?? 0;
-
- // We want the null reference exception to be launched here if target is null
var result = target!.Insert(index, value);
- StringBuilderModuleImpl.OnStringBuilderInsert(target, previousLength, index, value);
+ try
+ {
+ if (target is not null && value is not null)
+ {
+ var val = value.ToString();
+ var previousLength = target.Length - val!.Length;
+ StringBuilderModuleImpl.OnStringBuilderInsert(target!, previousLength, index, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Insert)}");
+ }
+
return result;
}
@@ -668,9 +1021,16 @@ public static StringBuilder Insert(StringBuilder? target, int index, object valu
[AspectMethodReplace("System.Text.StringBuilder::Remove(System.Int32,System.Int32)")]
public static StringBuilder Remove(StringBuilder? target, int startIndex, int length)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.Remove(startIndex, length);
- PropagationModuleImpl.OnStringRemove(target, result, startIndex, startIndex + length);
+ try
+ {
+ PropagationModuleImpl.OnStringRemove(target, result, startIndex, startIndex + length);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Remove)}");
+ }
+
return result;
}
@@ -682,9 +1042,16 @@ public static StringBuilder Remove(StringBuilder? target, int startIndex, int le
[AspectMethodReplace("System.Text.StringBuilder::Replace(System.String,System.String)")]
public static StringBuilder Replace(StringBuilder? target, string? oldValue, string? newValue)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.Replace(oldValue!, newValue);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, oldValue, newValue);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, oldValue, newValue);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Replace)}");
+ }
+
return result;
}
@@ -698,9 +1065,16 @@ public static StringBuilder Replace(StringBuilder? target, string? oldValue, str
[AspectMethodReplace("System.Text.StringBuilder::Replace(System.String,System.String,System.Int32,System.Int32)")]
public static StringBuilder Replace(StringBuilder? target, string? oldValue, string? newValue, int startIndex, int count)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.Replace(oldValue!, newValue, startIndex, count);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target, oldValue, newValue);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target, oldValue, newValue);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Replace)}");
+ }
+
return result;
}
@@ -712,9 +1086,16 @@ public static StringBuilder Replace(StringBuilder? target, string? oldValue, str
[AspectMethodReplace("System.Text.StringBuilder::Replace(System.Char,System.Char)")]
public static StringBuilder Replace(StringBuilder? target, char oldChar, char newChar)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.Replace(oldChar, newChar);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Replace)}");
+ }
+
return result;
}
@@ -728,9 +1109,16 @@ public static StringBuilder Replace(StringBuilder? target, char oldChar, char ne
[AspectMethodReplace("System.Text.StringBuilder::Replace(System.Char,System.Char,System.Int32,System.Int32)")]
public static StringBuilder Replace(StringBuilder? target, char oldChar, char newChar, int startIndex, int count)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.Replace(oldChar, newChar, startIndex, count);
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(Replace)}");
+ }
+
return result;
}
@@ -740,9 +1128,15 @@ public static StringBuilder Replace(StringBuilder? target, char oldChar, char ne
[AspectMethodReplace("System.Text.StringBuilder::set_Length(System.Int32)")]
public static void SetLength(StringBuilder? target, int length)
{
- // We want the null reference exception to be launched here if target is null
target!.Length = length;
- StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTainted(target);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(SetLength)}");
+ }
}
#if NETCOREAPP3_1_OR_GREATER
@@ -754,9 +1148,16 @@ public static void SetLength(StringBuilder? target, int length)
[AspectMethodReplace("System.Text.StringBuilder::AppendJoin(System.String,System.String[])")]
public static StringBuilder AppendJoin(StringBuilder? target, string? separator, string[]? values)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendJoin(separator, values!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, separator, values);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, separator, values);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendJoin)}");
+ }
+
return result;
}
@@ -768,9 +1169,16 @@ public static StringBuilder AppendJoin(StringBuilder? target, string? separator,
[AspectMethodReplace("System.Text.StringBuilder::AppendJoin(System.String,System.Object[])")]
public static StringBuilder AppendJoin(StringBuilder? target, string? separator, object[]? values)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendJoin(separator, values!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, separator, values);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, separator, values);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendJoin)}");
+ }
+
return result;
}
@@ -782,9 +1190,16 @@ public static StringBuilder AppendJoin(StringBuilder? target, string? separator,
[AspectMethodReplace("System.Text.StringBuilder::AppendJoin(System.Char,System.String[])")]
public static StringBuilder AppendJoin(StringBuilder? target, char separator, string[]? values)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendJoin(separator, values!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, null, values);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, null, values);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendJoin)}");
+ }
+
return result;
}
@@ -796,12 +1211,22 @@ public static StringBuilder AppendJoin(StringBuilder? target, char separator, st
[AspectMethodReplace("System.Text.StringBuilder::AppendJoin(System.Char,System.Object[])")]
public static StringBuilder AppendJoin(StringBuilder? target, char separator, object[]? values)
{
- // We want the null reference exception to be launched here if target is null
var result = target!.AppendJoin(separator, values!);
- StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, null, values);
+ try
+ {
+ StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, null, values);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringBuilderAspects)}.{nameof(AppendJoin)}");
+ }
+
return result;
}
+ // TODO : Add support for callsites with undefined generic params
+/*
+
/// StringBuilder.AppendJoin aspect
/// The StringBuilder instance.
/// The character to use as a separator.
@@ -889,5 +1314,6 @@ public static StringBuilder AppendJoin(StringBuilder? target, string? separator,
StringBuilderModuleImpl.FullTaintIfAnyTaintedEnumerable(target, separator, valuesConverted);
return result;
}
+*/
#endif
}
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web.Extensions/JavaScriptSerializerAspects.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web.Extensions/JavaScriptSerializerAspects.cs
index 91eea86c2e4f..423e3d100d7a 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web.Extensions/JavaScriptSerializerAspects.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web.Extensions/JavaScriptSerializerAspects.cs
@@ -31,6 +31,7 @@ public class JavaScriptSerializerAspects
/// The target url
[AspectMethodReplace("System.Web.Script.Serialization.JavaScriptSerializer::DeserializeObject(System.String)")]
public static object? DeserializeObject(object instance, string input)
+#pragma warning disable DD0005
{
IJavaScriptSerializer? serializer;
try
@@ -63,6 +64,7 @@ public class JavaScriptSerializerAspects
return result;
}
+#pragma warning restore DD0005
private static void TaintObject(object obj, TaintedObjects taintedObjects)
{
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpCookieAspect.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpCookieAspect.cs
index f2392f38b251..f0c94566a455 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpCookieAspect.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpCookieAspect.cs
@@ -6,6 +6,7 @@
#nullable enable
+using System;
using System.Web;
using Datadog.Trace.Iast.Dataflow;
using Datadog.Trace.Iast.Propagation;
@@ -29,10 +30,16 @@ public class HttpCookieAspect
public static string GetValue(HttpCookie cookie)
{
var value = cookie.Value;
-
- if (!string.IsNullOrEmpty(value))
+ try
+ {
+ if (!string.IsNullOrEmpty(value))
+ {
+ PropagationModuleImpl.AddTaintedSource(value, new Source(SourceType.CookieValue, cookie?.Name, value));
+ }
+ }
+ catch (Exception ex)
{
- PropagationModuleImpl.AddTaintedSource(value, new Source(SourceType.CookieValue, cookie?.Name, value));
+ IastModule.Log.Error(ex, $"Error invoking {nameof(HttpCookieAspect)}.{nameof(GetValue)}");
}
return value;
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpUtilityAspect.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpUtilityAspect.cs
index 9cd473e1c506..50ea2aa96f57 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpUtilityAspect.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System.Web/HttpUtilityAspect.cs
@@ -26,6 +26,19 @@ public class HttpUtilityAspect
[AspectMethodReplace("System.Web.HttpUtility::HtmlEncode(System.String)")]
public static string? Review(string? parameter)
{
- return IastModule.OnXssEscape(parameter);
+ var result = WebUtility.HtmlEncode(parameter);
+ try
+ {
+ if (parameter is not null && result is not null)
+ {
+ return IastModule.OnXssEscape(parameter, result);
+ }
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(HttpUtilityAspect)}.{nameof(Review)}");
+ }
+
+ return result;
}
}
diff --git a/tracer/src/Datadog.Trace/Iast/Aspects/System/StringAspects.cs b/tracer/src/Datadog.Trace/Iast/Aspects/System/StringAspects.cs
index 2825c7e122e1..f1a6d17c0b50 100644
--- a/tracer/src/Datadog.Trace/Iast/Aspects/System/StringAspects.cs
+++ b/tracer/src/Datadog.Trace/Iast/Aspects/System/StringAspects.cs
@@ -31,7 +31,17 @@ public class StringAspects
[AspectMethodReplace("System.String::Trim()", AspectFilter.StringLiteral_0)]
public static string Trim(string target)
{
- return StringModuleImpl.OnStringTrim(target, target.Trim(), null, true, true);
+ var result = target.Trim();
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, true, true);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Trim)}");
+ }
+
+ return result;
}
///
@@ -43,14 +53,24 @@ public static string Trim(string target)
[AspectMethodReplace("System.String::Trim(System.Char[])", AspectFilter.StringLiteral_0)]
public static string Trim(string target, char[] trimChars)
{
- if (trimChars != null && trimChars.Length > 0)
+ var result = target.Trim(trimChars);
+ try
{
- return StringModuleImpl.OnStringTrimArray(target, target.Trim(trimChars), trimChars, true, true);
+ if (trimChars != null && trimChars.Length > 0)
+ {
+ return StringModuleImpl.OnStringTrimArray(target, result, trimChars, true, true);
+ }
+ else
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, true, true);
+ }
}
- else
+ catch (Exception ex)
{
- return StringModuleImpl.OnStringTrim(target, target.Trim(trimChars), null, true, true);
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Trim)}");
}
+
+ return result;
}
#if !NETFRAMEWORK
@@ -63,7 +83,17 @@ public static string Trim(string target, char[] trimChars)
[AspectMethodReplace("System.String::Trim(System.Char)", AspectFilter.StringLiteral_0)]
public static string Trim(string target, char trimChar)
{
- return StringModuleImpl.OnStringTrim(target, target.Trim(trimChar), trimChar, true, true);
+ var result = target.Trim(trimChar);
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, trimChar, true, true);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Trim)}");
+ }
+
+ return result;
}
#endif
@@ -76,14 +106,24 @@ public static string Trim(string target, char trimChar)
[AspectMethodReplace("System.String::TrimStart(System.Char[])", AspectFilter.StringLiteral_0)]
public static string TrimStart(string target, char[] trimChars)
{
- if (trimChars != null && trimChars.Length > 0)
+ var result = target.TrimStart(trimChars);
+ try
{
- return StringModuleImpl.OnStringTrimArray(target, target.TrimStart(trimChars), trimChars, true, false);
+ if (trimChars != null && trimChars.Length > 0)
+ {
+ return StringModuleImpl.OnStringTrimArray(target, result, trimChars, true, false);
+ }
+ else
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, true, false);
+ }
}
- else
+ catch (Exception ex)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimStart(trimChars), null, true, false);
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimStart)}");
}
+
+ return result;
}
#if !NETFRAMEWORK
@@ -96,7 +136,17 @@ public static string TrimStart(string target, char[] trimChars)
[AspectMethodReplace("System.String::TrimStart(System.Char)", AspectFilter.StringLiteral_0)]
public static string TrimStart(string target, char trimChar)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimStart(trimChar), trimChar, true, false);
+ var result = target.TrimStart(trimChar);
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, trimChar, true, false);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimStart)}");
+ }
+
+ return result;
}
///
@@ -107,7 +157,17 @@ public static string TrimStart(string target, char trimChar)
[AspectMethodReplace("System.String::TrimStart()", AspectFilter.StringLiteral_0)]
public static string TrimStart(string target)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimStart(), null, true, false);
+ var result = target.TrimStart();
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, true, false);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimStart)}");
+ }
+
+ return result;
}
#endif
@@ -120,14 +180,24 @@ public static string TrimStart(string target)
[AspectMethodReplace("System.String::TrimEnd(System.Char[])", AspectFilter.StringLiteral_0)]
public static string TrimEnd(string target, char[] trimChars)
{
- if (trimChars != null && trimChars.Length > 0)
+ var result = target.TrimEnd(trimChars);
+ try
{
- return StringModuleImpl.OnStringTrimArray(target, target.TrimEnd(trimChars), trimChars, false, true);
+ if (trimChars != null && trimChars.Length > 0)
+ {
+ return StringModuleImpl.OnStringTrimArray(target, result, trimChars, false, true);
+ }
+ else
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, false, true);
+ }
}
- else
+ catch (Exception ex)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimEnd(trimChars), null, false, true);
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimEnd)}");
}
+
+ return result;
}
#if !NETFRAMEWORK
@@ -140,7 +210,17 @@ public static string TrimEnd(string target, char[] trimChars)
[AspectMethodReplace("System.String::TrimEnd(System.Char)", AspectFilter.StringLiteral_0)]
public static string TrimEnd(string target, char trimChar)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimEnd(trimChar), trimChar, false, true);
+ var result = target.TrimEnd(trimChar);
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, trimChar, false, true);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimEnd)}");
+ }
+
+ return result;
}
///
@@ -151,7 +231,17 @@ public static string TrimEnd(string target, char trimChar)
[AspectMethodReplace("System.String::TrimEnd()", AspectFilter.StringLiteral_0)]
public static string TrimEnd(string target)
{
- return StringModuleImpl.OnStringTrim(target, target.TrimEnd(), null, false, true);
+ var result = target.TrimEnd();
+ try
+ {
+ return StringModuleImpl.OnStringTrim(target, result, null, false, true);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(TrimEnd)}");
+ }
+
+ return result;
}
#endif
@@ -164,7 +254,17 @@ public static string TrimEnd(string target)
[AspectMethodReplace("System.String::Concat(System.String,System.String)", AspectFilter.StringLiterals_Any)]
public static string Concat(string param1, string param2)
{
- return StringModuleImpl.OnStringConcat(param1, param2, string.Concat(param1, param2));
+ var result = string.Concat(param1, param2);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(param1, param2, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
///
@@ -176,7 +276,17 @@ public static string Concat(string param1, string param2)
[AspectMethodReplace("System.String::Concat(System.String,System.String)", AspectFilter.StringLiteral_0)]
public static string Concat_0(string param1, string param2)
{
- return StringModuleImpl.OnStringConcat(param1, param2, string.Concat(param1, param2), AspectFilter.StringLiteral_0);
+ var result = string.Concat(param1, param2);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(param1, param2, result, AspectFilter.StringLiteral_0);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat_0)}");
+ }
+
+ return result;
}
///
@@ -188,7 +298,17 @@ public static string Concat_0(string param1, string param2)
[AspectMethodReplace("System.String::Concat(System.String,System.String)", AspectFilter.StringLiteral_1)]
public static string Concat_1(string param1, string param2)
{
- return StringModuleImpl.OnStringConcat(param1, param2, string.Concat(param1, param2), AspectFilter.StringLiteral_1);
+ var result = string.Concat(param1, param2);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(param1, param2, result, AspectFilter.StringLiteral_1);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat_1)}");
+ }
+
+ return result;
}
///
@@ -200,7 +320,17 @@ public static string Concat_1(string param1, string param2)
[AspectMethodReplace("System.String::Concat(System.Object,System.Object)")]
public static string Concat(object param1, object param2)
{
- return StringModuleImpl.OnStringConcat(param1?.ToString(), param2?.ToString(), string.Concat(param1, param2));
+ var result = string.Concat(param1, param2);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(param1?.ToString(), param2?.ToString(), result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
///
@@ -213,7 +343,17 @@ public static string Concat(object param1, object param2)
[AspectMethodReplace("System.String::Concat(System.String,System.String,System.String)", AspectFilter.StringLiterals)]
public static string Concat(string param1, string param2, string param3)
{
- return StringModuleImpl.OnStringConcat(new StringConcatParams(param1, param2, param3), string.Concat(param1, param2, param3));
+ var result = string.Concat(param1, param2, param3);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(new StringConcatParams(param1, param2, param3), result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
///
@@ -226,7 +366,17 @@ public static string Concat(string param1, string param2, string param3)
[AspectMethodReplace("System.String::Concat(System.Object,System.Object,System.Object)")]
public static string Concat(object param1, object param2, object param3)
{
- return StringModuleImpl.OnStringConcat(new StringConcatParams(param1?.ToString(), param2?.ToString(), param3?.ToString()), string.Concat(param1, param2, param3));
+ var result = string.Concat(param1, param2, param3);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(new StringConcatParams(param1?.ToString(), param2?.ToString(), param3?.ToString()), result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
///
@@ -240,7 +390,17 @@ public static string Concat(object param1, object param2, object param3)
[AspectMethodReplace("System.String::Concat(System.String,System.String,System.String,System.String)", AspectFilter.StringLiterals)]
public static string Concat(string param1, string param2, string param3, string param4)
{
- return StringModuleImpl.OnStringConcat(new StringConcatParams(param1, param2, param3, param4), string.Concat(param1, param2, param3, param4));
+ var result = string.Concat(param1, param2, param3, param4);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(new StringConcatParams(param1, param2, param3, param4), result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
#if NETFRAMEWORK
@@ -255,7 +415,17 @@ public static string Concat(string param1, string param2, string param3, string
[AspectMethodReplace("System.String::Concat(System.Object,System.Object,System.Object,System.Object)")]
public static string Concat(object param1, object param2, object param3, object param4)
{
- return StringModuleImpl.OnStringConcat(new StringConcatParams(param1?.ToString(), param2?.ToString(), param3?.ToString(), param4?.ToString()), string.Concat(param1, param2, param3, param4));
+ var result = string.Concat(param1, param2, param3, param4);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(new StringConcatParams(param1?.ToString(), param2?.ToString(), param3?.ToString(), param4?.ToString()), result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
#endif
@@ -267,7 +437,17 @@ public static string Concat(object param1, object param2, object param3, object
[AspectMethodReplace("System.String::Concat(System.String[])")]
public static string Concat(string[] values)
{
- return StringModuleImpl.OnStringConcat(values, string.Concat(values));
+ var result = string.Concat(values);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(values, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
+
+ return result;
}
///
@@ -278,19 +458,17 @@ public static string Concat(string[] values)
[AspectMethodReplace("System.String::Concat(System.Object[])")]
public static string Concat(object[] values)
{
- return StringModuleImpl.OnStringConcat(values, string.Concat(values));
- }
+ var result = string.Concat(values);
+ try
+ {
+ return StringModuleImpl.OnStringConcat(values, result);
+ }
+ catch (Exception ex)
+ {
+ IastModule.Log.Error(ex, $"Error invoking {nameof(StringAspects)}.{nameof(Concat)}");
+ }
- ///
- /// String.Concat aspect
- ///
- /// Parameters
- /// String.Concat(values)
- [AspectMethodReplace("System.String::Concat(System.Collections.Generic.IEnumerable`1)")]
- public static string Concat(IEnumerable values)
- {
- var valuesConverted = values as IEnumerable;
- return StringModuleImpl.OnStringConcat(valuesConverted, string.Concat(valuesConverted));
+ return result;
}
///
@@ -298,36 +476,24 @@ public static string Concat(IEnumerable values)
///
/// Parameters
/// String.Concat(values)
- [AspectMethodReplace("System.String::Concat(System.Collections.Generic.IEnumerable`1)")]
- public static string Concat2(IEnumerable values)
+ [AspectMethodReplace("System.String::Concat(System.Collections.Generic.IEnumerable`1)")]
+ public static string Concat(IEnumerable values)
{
- if (values is null)
- {
- return string.Concat(values);
- }
-
- var valuesConverted = values as IEnumerable