logo

Database

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.

Weakness:

134 - Insecure or unset HTTP headers - CORS

Category: Protocol Manipulation

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")...