Aalexbit-codemod

java-sql-injection-mining

Mine JDBC/JPA query sinks built from dynamic (non-literal) SQL that may be vulnerable to SQL injection (javasecurity:S3649); read-only metrics for security review

miningmetricsjavasecurityvulnerabilitysqlinjectionjdbccwe-89
Public
0 executions

Run locally

npx codemod java-sql-injection-mining

java-sql-injection-mining

Read-only mining codemod for SonarSource rule javasecurity:S3649Database queries should not be vulnerable to injection attacks.

It scans Java source and emits metrics only; it never modifies code (return null).
Findings are high-signal review candidates surfaced by AST pattern matching — they are
not proven vulnerabilities. A static mining pass cannot prove an end-to-end taint flow
from an untrusted source to the sink, so confirm data flow before remediating.

FieldValue
Rule keyjavasecurity:S3649
TypeVulnerability
SeverityBlocker
Primary CWECWE-89 (SQL Injection)
Tagsandroid, cwe, sql

What it detects

JDBC/JPA query sinks whose SQL argument is built from dynamic (non-literal) data.

Sinks:

  • Statement.executeQuery / execute / executeUpdate / executeLargeUpdate / addBatch
  • Connection.prepareStatement / prepareCall
  • EntityManager.createQuery / createNativeQuery, Hibernate createSQLQuery

Emission rule: Only emits when the query argument is not a constant string literal (e.g. concatenation, variable, or method call). Parameterized queries using ? placeholders with literal SQL are skipped.

Metric: java-sql-injection-mining

dimensionmeaning
ruleSonarSource rule key
cweprimary CWE identifier
severityalways blocker
sinkthe detected sink (method/constructor)
package_nameenclosing Java package
class_nameenclosing class/interface/enum/record
method_nameenclosing method/constructor (or <none>)
filefile path (relative to scan target)
line1-based line of the finding
arg_kindclassification of the relevant argument (literal, concatenation, variable, method_call, field, object_creation, expression, none)

Security standards

  • CWE-20 (Improper Input Validation)
  • CWE-89 (SQL Injection)
  • OWASP ASVS 4.0: 5.1.3, 5.1.4, 5.3.4, 5.3.5
  • OWASP Mobile Top 10 2024: M4
  • OWASP Top 10 2021: A3
  • OWASP Top 10: A1
  • PCI DSS 3.2: 6.5.1
  • PCI DSS 4.0: 6.2.4
  • STIG ASD V5R3: V-222607, V-222609

Run locally

bash

Part of the java-security-blocker-mining suite covering 19 blocker-severity
Java vulnerability rules. Each codemod is read-only and emits a single named metric.

Ready to contribute?

Build your own codemod and share it with the community.