logo

Database

Kotlin Path Traversal Unsanitized Param

Description

Detects path traversal vulnerabilities in Kotlin applications using JAX-RS framework where file paths from user input are not properly sanitized. This could allow attackers to access files outside the intended directory using path manipulation techniques like "../" sequences.

Weakness:

063 - Lack of data validation - Path Traversal

Category: Unexpected Injection

Detection Strategy

    Verifies that the application imports javax.ws.rs packages indicating JAX-RS usage

    Identifies endpoints that handle file operations using dangerous methods like File(), Paths.get(), or similar file manipulation functions

    Checks if these file operations use parameters directly from user input without proper path sanitization

    Reports a vulnerability when file operations use unvalidated input parameters that could allow directory traversal

Vulnerable code example

import java.io.File
import java.nio.file.Paths
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam

@Path("/api")
class VulnerableEndpoint {...

✅ Secure code example

import org.apache.commons.io.FilenameUtils
import java.io.File
import java.nio.file.Paths
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.core.Response
...