Skip to content

Java: Exclude test files from java/concatenated-sql-query#8

Open
kiro-agent[bot] wants to merge 1 commit into
mainfrom
improve-java-sql-concatenated-exclude-tests
Open

Java: Exclude test files from java/concatenated-sql-query#8
kiro-agent[bot] wants to merge 1 commit into
mainfrom
improve-java-sql-concatenated-exclude-tests

Conversation

@kiro-agent

@kiro-agent kiro-agent Bot commented Jun 14, 2026

Copy link
Copy Markdown

This pull request was created by @kiro-agent on behalf of @mrigankpawagi 👻

Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro Web


Summary

This PR improves the java/concatenated-sql-query query by excluding results that occur in test files.

Problem

MRVA on the top-100 Java repositories produced 382 alerts. Analysis of the results showed that 278 out of 382 alerts (73%) were in test files. These include:

  • JUnit test classes (JDBCRealmTest.java, ConnectionTest.java, StatementRegressionTest.java, etc.)
  • Test fixture setup code inserting sample data (e.g., sql.executeUpdate("insert into users values ('" + username + "'..."))
  • Integration tests for database libraries (H2, MySQL connector, PostgreSQL JDBC)

SQL concatenation in test code is used for test setup and fixture creation — it does not represent a real security vulnerability since:

  1. Test code is not deployed to production
  2. The concatenated values come from test constants, not user input
  3. The intent is testing, not building production queries

Changes

  • Modified java/ql/src/Security/CWE/CWE-089/SqlConcatenated.ql to add not isInTestFile(query.asExpr().getFile()) condition
  • Used the existing isInTestFile predicate from semmle.code.java.dataflow.internal.ModelExclusions which already handles standard test directory patterns

MRVA Validation

  • Before: 382 alerts across top-100 Java repositories
  • After (estimated): ~104 alerts (73% reduction)
  • All eliminated alerts were in test files and confirmed as false positives
  • True positives in production code are unaffected

Repositories with most test-file FPs eliminated

Repository Test FP alerts removed
mysql/mysql-connector-j ~55
h2database/h2database ~58
apache/incubator-seata ~24
apache/shiro ~10
liquibase/liquibase ~5

@github-actions github-actions Bot added documentation Improvements or additions to documentation Java labels Jun 14, 2026
@mrigankpawagi mrigankpawagi force-pushed the improve-java-sql-concatenated-exclude-tests branch from 2c9768c to 3c09dc5 Compare June 23, 2026 12:03
@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant