fix(java/jdo-sqli): detect String.formatted() as a tainted query source - #4016
Open
rayair250-droid wants to merge 1 commit into
Open
fix(java/jdo-sqli): detect String.formatted() as a tainted query source#4016rayair250-droid wants to merge 1 commit into
rayair250-droid wants to merge 1 commit into
Conversation
The jdo-sqli rule flagged String.format(...) and string concatenation passed to JDO query APIs (setFilter/setGrouping/newQuery), but missed the Java 15+ instance method "...".formatted(input), which produces the same attacker-controlled query string. Add matching patterns (both as a pattern-inside source and as a direct argument) mirroring the existing String.format handling, plus test cases. Validated with semgrep --test. Closes semgrep#3812.
|
|
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.
Closes #3812.
Problem
java/lang/security/audit/sqli/jdo-sqliflags a formatted/concatenated string passed to JDO query APIs (setFilter/setGrouping/newQuery). It already handlesString.format(...)and$X + $Yconcatenation, but misses the Java 15+ instance method"...".formatted(input), which produces the exact same attacker-controlled query string:Reproduction scanned with 0 findings before this change — a SQL-injection false negative.
Fix
Mirror the existing
String.format(...)handling with"...".formatted(...)patterns, in both theQueryandPersistenceManagerbranches — as apattern-insidesource (String $SQL = "...".formatted(...);) and as a direct argument ($Q.$METHOD("...".formatted(...),...)/$PM.newQuery(...,"...".formatted(...),...)).Added
// ruleid:test cases for the new patterns.semgrep --testreports All tests passed (existing// ok:cases still don't match).