Skip to content

fix(java/jdo-sqli): detect String.formatted() as a tainted query source - #4016

Open
rayair250-droid wants to merge 1 commit into
semgrep:developfrom
rayair250-droid:fix/jdo-sqli-formatted
Open

fix(java/jdo-sqli): detect String.formatted() as a tainted query source#4016
rayair250-droid wants to merge 1 commit into
semgrep:developfrom
rayair250-droid:fix/jdo-sqli-formatted

Conversation

@rayair250-droid

Copy link
Copy Markdown

Closes #3812.

Problem

java/lang/security/audit/sqli/jdo-sqli flags a formatted/concatenated string passed to JDO query APIs (setFilter/setGrouping/newQuery). It already handles String.format(...) and $X + $Y concatenation, but misses the Java 15+ instance method "...".formatted(input), which produces the exact same attacker-controlled query string:

q.setFilter("id == %s".formatted(filterValue));               // was NOT flagged
pm.newQuery(UserEntity.class, "id == %s".formatted(input));   // was NOT flagged

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 the Query and PersistenceManager branches — as a pattern-inside source (String $SQL = "...".formatted(...);) and as a direct argument ($Q.$METHOD("...".formatted(...),...) / $PM.newQuery(...,"...".formatted(...),...)).

Added // ruleid: test cases for the new patterns. semgrep --test reports All tests passed (existing // ok: cases still don't match).

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.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java] false negative: jdo-sqli misses "...".formatted(input) pattern.

2 participants