Add Java CWE-089 SQL injection audit query (partial flow, any source) - #198
Merged
Merged
Conversation
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
felickz
July 31, 2026 19:31
View session
felickz
marked this pull request as ready for review
July 31, 2026 19:31
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
java/src/audit/CWE-089/SqlInjectionAudit.ql:43
- The result message/label says “user-provided value”, but the configuration treats any node as a source (including string literals, as shown by the included expected output). This wording is inaccurate and can confuse audit triage; consider a neutral label (for example, “value”) and a message that doesn’t imply user control. Note: changing this will require updating the .expected test output accordingly.
select sink.getNode(), source, sink, "This SQL query depends on a $@.", source.getNode(),
"user-provided value"
java/src/audit/CWE-089/SqlInjectionAudit.ql:6
- The query considers every node a potential source (
isSource { any() }), but the @name/@description currently describe only “user-controlled sources”. This is misleading for an audit query intended to surface any influencing value (including literals and internal data). Update the metadata to match the query’s actual scope.
This issue also appears on line 42 of the same file.
* @name SQL query built from user-controlled sources
* @description Building a SQL query from user-controlled sources is vulnerable to insertion of
* malicious SQL code by the user. This audit query reports partial flows (any
* source, not just recognized remote/user input) into a known SQL injection sink,
* which is useful for surfacing sources that are not yet modeled.
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
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.
Java lacked an audit query for CWE-089 SQL injection, unlike the existing Python
SqlInjectionAudit.ql. The goal is to surface any data flowing into a recognized SQL injection sink, including from sources not modeled as user input.Query
java/src/audit/CWE-089/SqlInjectionAudit.ql: a partial (backwards) taint-tracking exploration fromQueryInjectionSink(coversStatement.executeQuery,Connection.prepareStatement, etc.), withisSourcematching any node viaTaintTracking::Global+FlowExplorationRev.audit/ kindpath-problem, so it's automatically picked up byjava-audit.qlsand excluded from the defaultjava.qls, consistent with other audit queries.Docs
java/src/audit/CWE-089/SqlInjectionAudit.mddescribing the query's purpose and low-precision, audit-only nature.Tests
java/test/audit/CWE-089/withSqlInjectionAuditTest.java(tainted concatenation + hardcoded literal cases),.qlref, and accepted.expectedoutput.