Java: Improve saneString in java/concatenated-command-line using controlledString + test exclusion#12
Open
mrigankpawagi wants to merge 1 commit into
Open
Conversation
…st exclusion Replace the saneString predicate body with controlledString (from the ControlledString library) and CompileTimeConstantExpr to reduce false positives. Also exclude results in test files using isInTestFile from ModelExclusions. This consolidates the approaches from PRs #5 and #10 into a single coherent change.
This was referenced Jun 15, 2026
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 #5 and #10, combining the best of both approaches to improve the
java/concatenated-command-linequery (ExecUnescaped.ql).Problem
The existing
saneStringpredicate was overly simplistic — it only recognizedStringLiteral,NullLiteral, and variables assigned from those. This caused many false positives for expressions that are clearly programmer-controlled.Changes (consolidated from #5 and #10)
From PR #5: Use shared
controlledStringpredicateReplaced the ad-hoc
saneStringbody withcontrolledString(expr)fromsemmle.code.java.security.ControlledString. This is the same predicate already used bySqlConcatenated.qland covers:.getName(),.getSimpleName()).toString()From PR #10: CompileTimeConstantExpr + test exclusion
expr instanceof CompileTimeConstantExprsince this is NOT covered bycontrolledStringbut capturesstatic finalfields and other compile-time constantsnot isInTestFile(argument.getFile())to exclude test files where command concatenation is used for test setupWhy this consolidation is better than either PR alone
Supersedes: #5, #10