An SQL query is built from strings with values in them
What it finds
db.rawQuery("SELECT * FROM users WHERE name = '$name'", null) lets a value with a quote change the query, so a crafted name reads or deletes other data. Placeholders with bound arguments keep values out of the SQL.
Reported for rawQuery, execSQL, executeQuery, executeUpdate, execute, prepareStatement, createQuery and createNativeQuery when the query is a string with templates, or built with +, and starts like SQL.
From the rule's source, query_from_strings.rs.
fun find(db: SQLiteDatabase, name: String, table: String) { db.rawQuery("SELECT * FROM users WHERE name = '$name'", null)tx0 reports: the query passed to rawQuery is built from strings db.execSQL("DELETE FROM users WHERE name = '" + name + "'")tx0 reports: the query passed to execSQL db.rawQuery("SELECT * FROM users WHERE name = ?", arrayOf(name)) db.execSQL("SELECT 1") db.execSQL("DELETE FROM $TABLE WHERE " + "id = 1") log.execute("running $name")} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:sql-built-from-strings" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:sql-built-from-strings] reason="..."tx0 explain tx0/kotlin:sql-built-from-strings shows the same in the terminal. Found a false positive? Report it.