Java: Improve java/log-injection with DEBUG/TRACE exclusion, URLEncoder sanitizer, and test file exclusion#13
Open
mrigankpawagi wants to merge 1 commit into
Open
Conversation
This was referenced Jun 15, 2026
…t exclusion, and DEBUG/TRACE level exclusion - Add java.net.URLEncoder.encode() as a sanitizer since URL encoding replaces line breaks with percent-encoded equivalents - Exclude results in test files to reduce noise from non-production code - Exclude DEBUG/TRACE level logging methods (debug, trace, fine, finer, finest) from sinks since these are typically disabled in production
eaab7c3 to
8068355
Compare
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
This PR consolidates and supersedes PRs #7 and #11, combining all three improvements to the
java/log-injectionquery into a single PR.Problem
MRVA on top-100 Java repositories showed 5,958 log injection alerts. Analysis identified three improvement opportunities:
URLEncoder.encode()was not recognized as a sanitizer — URL encoding converts\nto%0A, preventing log injectionChanges
1. Exclude DEBUG/TRACE level logging from sinks (from PR #7)
Modified
DefaultLogInjectionSinkinLogInjection.qllto exclude method calls to:debug,trace(SLF4J, Log4j, Commons Logging, JBoss Logging)fine,finer,finest(java.util.logging)2. Add
URLEncoder.encode()as sanitizer (from PR #11)Added
UrlEncoderSanitizerclass recognizingjava.net.URLEncoder.encode()as a sanitizer since URL encoding replaces line breaks with percent-encoded equivalents.3. Exclude test files (from PR #11)
Added
not isInTestFile(...)to the query using the existingModelExclusionspredicate.MRVA Validation
Why each change is correct
URLEncoder.encode(input, "UTF-8")converts\n→%0A,\r→%0D— no raw newlines survive.Supersedes: #7, #11