In our Java-project I need to find potential SQL-injections in the java source files.
We use our own Java-SQL frontend class and all relevant SQL-queries are in the following form:
String someText = "potential SQL injection";
SQL.selectInto(
"SELECT C.LANGUAGE, " +
someText +
"FROM COMPANY C " +
"WHERE C.COMPANY_NR = :companyNr " +
"INTO :languageUid ",
new NVPair("companyNr", companyNr),
new NVPair("languageUid", languageUid)
);
The problem is, that the variable "someText" could potentially contain another SQL-string which might cause an SQL-injection.
I am looking for a way (regular expression, java parser, etc...) to find all java-string literals with SQL in it, which have some kind of string concatenation which might contain a SQL-snippet, so that I could inspect this instances manually and rewrite them if necessary.
I assume that SQL-stmts are only used with the SQL-helper class like:
SQL.select(...)
SQL.insert(...)