Kotlin Insecure Cors Origin
Description
Detects insecure CORS (Cross-Origin Resource Sharing) configurations in Kotlin applications using the Ktor framework. Insecure CORS settings that allow unrestricted cross-origin access can enable malicious websites to make unauthorized requests to your application, potentially leading to data theft or unauthorized actions.
Detection Strategy
• Examines Kotlin source files that use the Ktor web framework
• Identifies CORS configuration blocks in the application code
• Reports a vulnerability when CORS settings allow overly permissive origins like '*' or accept all origins without proper validation
• Checks specific CORS-related method calls and configurations that control cross-origin access
Vulnerable code example
import io.ktor.server.application.*
import io.ktor.server.plugins.cors.routing.*
fun Application.configureServer() {
install(CORS) {
// VULNERABLE: Allows any origin to access resources by setting Access-Control-Allow-Origin: *
anyHost()
}...✅ Secure code example
import io.ktor.server.application.*
import io.ktor.server.plugins.cors.routing.*
fun Application.configureServer() {
install(CORS) {
// SECURE: Explicitly specify allowed origins instead of allowing any host
allowHost("trusted-domain.com", subDomains = listOf("api", "www"))
allowHost("another-trusted-domain.org")...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.