Skip to content

Add Java CWE-089 SQL injection audit query (partial flow, any source) - #198

Merged
felickz merged 1 commit into
mainfrom
copilot/create-cwe-089-sql-injection-query
Jul 31, 2026
Merged

Add Java CWE-089 SQL injection audit query (partial flow, any source)#198
felickz merged 1 commit into
mainfrom
copilot/create-cwe-089-sql-injection-query

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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

  • Added java/src/audit/CWE-089/SqlInjectionAudit.ql: a partial (backwards) taint-tracking exploration from QueryInjectionSink (covers Statement.executeQuery, Connection.prepareStatement, etc.), with isSource matching any node via TaintTracking::Global + FlowExplorationRev.
  • Tagged audit / kind path-problem, so it's automatically picked up by java-audit.qls and excluded from the default java.qls, consistent with other audit queries.
Statement statement = connection.createStatement();
// Reported even though `username` may not be recognized as a RemoteFlowSource
statement.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");

Docs

  • Added java/src/audit/CWE-089/SqlInjectionAudit.md describing the query's purpose and low-precision, audit-only nature.

Tests

  • Added java/test/audit/CWE-089/ with SqlInjectionAuditTest.java (tainted concatenation + hardcoded literal cases), .qlref, and accepted .expected output.

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@felickz
felickz marked this pull request as ready for review July 31, 2026 19:31
@felickz
felickz requested a review from Copilot July 31, 2026 19:33
Comment thread java/test/audit/CWE-089/SqlInjectionAuditTest.java Dismissed
Comment thread java/test/audit/CWE-089/SqlInjectionAuditTest.java Dismissed
Comment thread java/test/audit/CWE-089/SqlInjectionAuditTest.java Dismissed
Comment thread java/test/audit/CWE-089/SqlInjectionAuditTest.java Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@felickz felickz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:octocat: 👍

@felickz
felickz merged commit bbfde1b into main Jul 31, 2026
24 checks passed
@felickz
felickz deleted the copilot/create-cwe-089-sql-injection-query branch July 31, 2026 20:11
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.

3 participants