Why it matters
If any interpolated value ever carries caller-supplied data, including through another function, this is SQL injection.
How to fix it
Keep the statement constant and bind the values.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
class OrderRepository(private val conn: Connection) {
fun byCustomer(customer: String): ResultSet =
conn.createStatement().executeQuery("SELECT id FROM orders WHERE customer = '$customer'")
}class OrderRepository(private val conn: Connection) {
fun byCustomer(customer: String): ResultSet {
val ps = conn.prepareStatement("SELECT id FROM orders WHERE customer = ?")
ps.setString(1, customer)
return ps.executeQuery()
}
}What TrustIvan reads
Runs on repository scans of Kotlin source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Header injection from request input (Kotlin)
KotlinSeverity: Medium
trustivan-kotlin-taint-header-injection - Weak hash (Kotlin)
KotlinSeverity: Medium
trustivan-kotlin-weak-hash - Regex injection from request input (Kotlin)
KotlinSeverity: Medium
trustivan-kotlin-taint-regex-injection - Weak cipher (Kotlin)
KotlinSeverity: High
trustivan-kotlin-weak-cipher - Expression injection from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-expression-injection - Insecure random secret (Kotlin)
KotlinSeverity: Medium
trustivan-kotlin-insecure-random-secret
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation