Why it matters
The caller controls part of the statement, so they can change what it selects, updates or deletes.
How to fix it
Keep the statement text constant and pass the value as a bind parameter (JdbcTemplate's varargs, PreparedStatement.setString, or Exposed's DSL).
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
@RestController
class OrderController(private val jdbc: JdbcTemplate) {
@GetMapping("/orders")
fun list(@RequestParam("status") status: String): List<Map<String, Any>> =
jdbc.queryForList("SELECT id FROM orders WHERE status = '$status'")
}@RestController
class OrderController(private val jdbc: JdbcTemplate) {
@GetMapping("/orders")
fun list(@RequestParam("status") status: String): List<Map<String, Any>> =
jdbc.queryForList("SELECT id FROM orders WHERE status = ?", status)
}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
- Command injection from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-command-injection - Path traversal from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-path-traversal - SSRF from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-ssrf - XSS from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-xss - Deserialization from request input (Kotlin)
KotlinSeverity: High
trustivan-kotlin-taint-deserialization - Open redirect from request input (Kotlin)
KotlinSeverity: Medium
trustivan-kotlin-taint-open-redirect
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