flawopen.com/Command Injection/Kotlin
Imagine asking someone to mail a package. If they let the sender write 'Deliver to Bob AND rob the bank' on the label and the delivery person does both, that is command injection.
In Kotlin applications (Ktor, Spring Boot with Kotlin, or Android), string templates ("cmd $userInput") passed to Runtime.getRuntime().exec() cause command injection.
Android root utilities and backend Ktor services have suffered privilege escalation when executing su commands or system utilities with unvalidated intent extras.
Common Vulnerabilities and Exposures (CVE) database.// String template with Runtime.exec
fun checkHost(host: String) {
// Input: "8.8.8.8; id"
val cmd = "ping -c 1 $host"
Runtime.getRuntime().exec(arrayOf("sh", "-c", cmd))
}
// ProcessBuilder with discrete list of arguments
fun checkHost(host: String) {
// host is isolated as a single argument
val command = listOf("ping", "-c", "1", host)
ProcessBuilder(command).start()
}
ProcessBuilder passes the command and its arguments as discrete strings to the kernel, preventing shell interpretation.
Executing su -c "$command" in rooted Android environments re-introduces full shell command injection. Always parameterize and restrict root access.
Null safety ensures variables are non-null; it does not check if the non-null string contains malicious shell characters.
grep -rn "Runtime.getRuntime().exec" --include="*.kt" .
ProcessBuilder(listOf(...))arrayOf("sh", "-c", ...)Yes, java.lang.ProcessBuilder is supported on all Android API levels.