Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASM] Normalise aspects exception logging #6495

Merged
merged 5 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async Task<Document> AddTryCatch(Document document, MethodDeclarationSyn
// create the trystatementsyntax with the internals of the method declaration
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}})}")"""));
SyntaxFactory.ParseExpression($$"""IastModule.LogAspectException(ex, $"{nameof({{typeName}})}.{nameof({{methodName}})}")"""));
var returnStatement = paramName is not null
? SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName(paramName))
: SyntaxFactory.ReturnStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async Task<Document> AddTryCatch(Document document, MethodDeclarationSyn

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}})}")"""));
SyntaxFactory.ParseExpression($$"""IastModule.LogAspectException(ex, $"{nameof({{typeName}})}.{nameof({{methodName}})}")"""));

var catchSyntax = SyntaxFactory.CatchClause()
.WithDeclaration(catchDeclaration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class HttpResponseAspect
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(HttpResponseAspect)}.{nameof(Redirect)}");
IastModule.LogAspectException(ex, $"{nameof(HttpResponseAspect)}.{nameof(Redirect)}");
return url;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ControllerBaseAspect
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(ControllerBaseAspect)}.{nameof(Redirect)}");
IastModule.LogAspectException(ex, $"{nameof(ControllerBaseAspect)}.{nameof(Redirect)}");
return url;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static object ReviewSqlCommand(object command)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(EntityCommandAspect)}.{nameof(ReviewSqlCommand)}");
IastModule.LogAspectException(ex, $"{nameof(EntityCommandAspect)}.{nameof(ReviewSqlCommand)}");
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static object ReviewSqlString(string sqlAsString)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(EntityFrameworkCoreAspect)}.{nameof(ReviewSqlString)}");
IastModule.LogAspectException(ex, $"{nameof(EntityFrameworkCoreAspect)}.{nameof(ReviewSqlString)}");
return sqlAsString;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static object AnalyzeJsonString(string json)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(BsonAspect)}.{nameof(AnalyzeJsonString)}");
IastModule.LogAspectException(ex, $"{nameof(BsonAspect)}.{nameof(AnalyzeJsonString)}");
return json;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class MongoDatabaseAspect

return command;
}
catch (global::System.Exception ex)
catch (Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(MongoDatabaseAspect)}.{nameof(AnalyzeCommand)}");
IastModule.LogAspectException(ex, $"{nameof(MongoDatabaseAspect)}.{nameof(AnalyzeCommand)}");
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static object AnalyzeQuery(string query)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(ISessionAspect)}.{nameof(AnalyzeQuery)}");
IastModule.LogAspectException(ex, $"{nameof(ISessionAspect)}.{nameof(AnalyzeQuery)}");
return query;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static NewtonsoftJsonAspects()
}
catch (Exception ex)
{
IastModule.Log.Error(ex, "Error while initializing NewtonsoftJsonAspects");
IastModule.LogAspectException(ex, $"{nameof(NewtonsoftJsonAspects)}.Ctor");
}
}

Expand All @@ -85,7 +85,7 @@ static NewtonsoftJsonAspects()
}
catch (Exception ex)
{
IastModule.Log.Error(ex, "Error while tainting the JObject");
IastModule.LogAspectException(ex, $"{nameof(NewtonsoftJsonAspects)}.{nameof(ParseObject)}");
}

return result;
Expand Down Expand Up @@ -113,7 +113,7 @@ static NewtonsoftJsonAspects()
}
catch (Exception ex)
{
IastModule.Log.Error(ex, "Error while tainting the JArray");
IastModule.LogAspectException(ex, $"{nameof(NewtonsoftJsonAspects)}.{nameof(ParseArray)}");
}

return result;
Expand All @@ -136,7 +136,7 @@ static NewtonsoftJsonAspects()
}
catch (Exception ex)
{
IastModule.Log.Error(ex, "Error while tainting the JToken");
IastModule.LogAspectException(ex, $"{nameof(NewtonsoftJsonAspects)}.{nameof(ParseToken)}");
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static object ReviewExecuteNonQuery(object command)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(DbCommandAspect)}.{nameof(ReviewExecuteNonQuery)}");
IastModule.LogAspectException(ex, $"{nameof(DbCommandAspect)}.{nameof(ReviewExecuteNonQuery)}");
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static object Init(string path)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(DirectoryEntryAspect)}.{nameof(Init)}");
IastModule.LogAspectException(ex, $"{nameof(DirectoryEntryAspect)}.{nameof(Init)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static object Init(string path)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(DirectorySearcherAspect)}.{nameof(Init)}");
IastModule.LogAspectException(ex, $"{nameof(DirectorySearcherAspect)}.{nameof(Init)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static object Init(string path)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(PrincipalContextAspect)}.{nameof(Init)}");
IastModule.LogAspectException(ex, $"{nameof(PrincipalContextAspect)}.{nameof(Init)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static object Init(object path)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(SearchRequestAspect)}.{nameof(Init)}");
IastModule.LogAspectException(ex, $"{nameof(SearchRequestAspect)}.{nameof(Init)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(DirectoryAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(DirectoryAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(DirectoryInfoAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(DirectoryInfoAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(FileAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(FileAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public static string ReviewPathRead(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(FileAspect)}.{nameof(ReviewPathRead)}");
IastModule.LogAspectException(ex, $"{nameof(FileAspect)}.{nameof(ReviewPathRead)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(FileInfoAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(FileInfoAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(FileStreamAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(FileStreamAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static string ReviewPath(string path)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(StreamReaderAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(StreamReaderAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static string ReviewPath(string path)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(StreamWriterAspect)}.{nameof(ReviewPath)}");
IastModule.LogAspectException(ex, $"{nameof(StreamWriterAspect)}.{nameof(ReviewPath)}");
return path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SmtpClientAspect
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(SmtpClientAspect)}.{nameof(Send)}");
IastModule.LogAspectException(ex, $"{nameof(SmtpClientAspect)}.{nameof(Send)}");
return message;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static string Review(string parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(HttpClientAspect)}.{nameof(Review)}");
IastModule.LogAspectException(ex, $"{nameof(HttpClientAspect)}.{nameof(Review)}");
return parameter;
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public static Uri ReviewUri(Uri parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(HttpClientAspect)}.{nameof(ReviewUri)}");
IastModule.LogAspectException(ex, $"{nameof(HttpClientAspect)}.{nameof(ReviewUri)}");
return parameter;
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public static HttpRequestMessage ReviewHttpRequestMessage(HttpRequestMessage par
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(HttpClientAspect)}.{nameof(ReviewHttpRequestMessage)}");
IastModule.LogAspectException(ex, $"{nameof(HttpClientAspect)}.{nameof(ReviewHttpRequestMessage)}");
return parameter;
}
}
Expand All @@ -166,7 +166,7 @@ public static object ReviewHttpRequestMessage(object parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(HttpClientAspect)}.{nameof(ReviewHttpRequestMessage)}");
IastModule.LogAspectException(ex, $"{nameof(HttpClientAspect)}.{nameof(ReviewHttpRequestMessage)}");
return parameter;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static string Review(string parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebClientAspect)}.{nameof(Review)}");
IastModule.LogAspectException(ex, $"{nameof(WebClientAspect)}.{nameof(Review)}");
return parameter;
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public static Uri ReviewUri(Uri parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebClientAspect)}.{nameof(ReviewUri)}");
IastModule.LogAspectException(ex, $"{nameof(WebClientAspect)}.{nameof(ReviewUri)}");
return parameter;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static string Review(string parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebRequestAspect)}.{nameof(Review)}");
IastModule.LogAspectException(ex, $"{nameof(WebRequestAspect)}.{nameof(Review)}");
return parameter;
}
}
Expand All @@ -56,7 +56,7 @@ public static Uri Review(Uri parameter)
}
catch (Exception ex) when (ex is not BlockException)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebRequestAspect)}.{nameof(Review)}");
IastModule.LogAspectException(ex, $"{nameof(WebRequestAspect)}.{nameof(Review)}");
return parameter;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class WebUtilityAspect
}
catch (Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebUtilityAspect)}.{nameof(XssEscape)}");
IastModule.LogAspectException(ex, $"{nameof(WebUtilityAspect)}.{nameof(XssEscape)}");
}

return result;
Expand All @@ -60,7 +60,7 @@ public class WebUtilityAspect
}
catch (Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(WebUtilityAspect)}.{nameof(SsrfEscape)}");
IastModule.LogAspectException(ex, $"{nameof(WebUtilityAspect)}.{nameof(SsrfEscape)}");
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static string ReflectionInjectionParam(string param)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(ActivatorAspect)}.{nameof(ReflectionInjectionParam)}");
IastModule.LogAspectException(ex, $"{nameof(ActivatorAspect)}.{nameof(ReflectionInjectionParam)}");
return param;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static string ReflectionAssemblyInjection(string assemblyString)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(AssemblyAspect)}.{nameof(ReflectionAssemblyInjection)}");
IastModule.LogAspectException(ex, $"{nameof(AssemblyAspect)}.{nameof(ReflectionAssemblyInjection)}");
return assemblyString;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static string ReflectionInjectionParam(string param)
}
catch (global::System.Exception ex)
{
IastModule.Log.Error(ex, $"Error invoking {nameof(TypeAspect)}.{nameof(ReflectionInjectionParam)}");
IastModule.LogAspectException(ex, $"{nameof(TypeAspect)}.{nameof(ReflectionInjectionParam)}");
return param;
}
}
Expand Down
Loading
Loading