fix(java): detect String.formatted() in jdo-sqli - #4023
Conversation
The rule matched String.format(...) but not the instance form "...%s...".formatted(input), so the same query built with the newer API went unreported. Add the formatted() variants next to each String.format() pattern. The new patterns require at least one argument, so a constant string with no interpolation is not flagged. Signed-off-by: Eljees <3.14hell@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da17133a16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Both points are fair; here's how I'd weigh them. Non-literal format templates ( Format strings that consume no arguments ( Tell me if you'd prefer the wider receiver, and I'll extend it consistently across both APIs. |
Signed-off-by: Eljees <3.14hell@gmail.com>
|
Ping — open since 28 July, no review yet. All checks are green on
The two points from the automated review are answered in the thread: the format string that consumes no arguments is handled, and widening the receiver to non-literal templates is deliberately left out — |
Fixes #3812
Problem
jdo-sqlimatchesString.format(...), but not the instance form added in Java 15:Both build the same query from the same input, so the newer spelling was a false negative.
Change
Adds a
formatted()variant next to each existingString.format(...)pattern — the twopattern-insideforms for a query held in a local variable, and the direct$Q.$METHOD(...)/$PM.newQuery(...)calls.The new patterns are written as
"...".formatted($X,...), i.e. they require at least one argument. A constant string with nothing interpolated ("select * from Config".formatted()) cannot carry user input, so it stays unreported — that case is included in the test file as anokannotation.Tests
java/lang/security/audit/sqli/jdo-sqli.javagains atestJdoQueriesFormattedblock covering both reproducers from the issue plus the argument-less negative case.