Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Log injection / log forging is one of the biggest sources of false positive flaws from CodeQL according to this analysis and my own personal experience.
This change prevents false positives from
cs/log-forgingwhen all present logging configuration uses a safe JSON format, either from .NET or Serilog.The query suppresses alerts for standard
Microsoft.Extensions.Loggingand Serilog logging calls only when a conservative, database-wide configuration check succeeds. It recognizes supported code-configured JSON logging setups and deliberately retains alerts whenever it finds a potentially incompatible, unresolved, or unsupported logging configuration.Over time this could be extended to support additional popular logging frameworks or safe output formats. In particular .NET 11 may soon have a safe console logger.
Risks
This is intentionally a database-wide heuristic: if it incorrectly classifies an application as JSON-only, it can suppress genuine
cs/log-forgingresults throughout that database.The false-negative risk is primarily configuration that is not visible or not recognized by the extractor/model—for example, logging changes in external dependencies, reflection, runtime-loaded configuration, or an external extension method that mutates logging without exposing a logging-related signature. The implementation partially mitigates this by requiring narrow recognized patterns and by vetoing on visible ambiguity or unsupported configuration, at the cost of retaining some false positives.
Suppression criteria
Suppression requires both positive evidence of a supported JSON-only configuration and no vetoing configuration anywhere visible in the database.
Recognized configurations are:
LoggerFactory.Createcallbacks that configureAddJsonConsole().ClearProviders();AddJsonConsole();Build().AddSerilogconfiguration callbacks that unconditionally configure supported JSON-formatted console, audit-console, or file sinks, including supportedWriteTo.Asyncwrappers.JsonFormatterwith an omitted ornullclosingDelimiter, andCompactJsonFormatter/RenderedCompactJsonFormatterwith their default formatter or a built-inJsonValueFormatter.writeToProvidersandpreserveStaticLoggermust be omitted orfalse.Suppression applies only to calls to supported framework logger APIs whose receiver is a library-provided
Microsoft.Extensions.Loggingor Serilog logger type. It does not suppress non-logger sinks such as tracing APIs or source-defined logger implementations.Conservative vetoes
The suppression is disabled if the database contains, among other things:
Build();new LoggerFactory()construction;ILoggerimplementations; orTests
Added coverage for:
HostApplicationBuilder, and service-registration setup;