logo

Database

Kotlin Cookie Missing Secure Flag

Description

Detects when cookies are created without the secure flag in Kotlin applications. Cookies without the secure flag can be transmitted over insecure HTTP connections, potentially exposing sensitive information to attackers who can intercept network traffic.

Weakness:

130 - Insecurely generated cookies - Secure

Category: Access Subversion

Detection Strategy

    Monitor for cookie creation using 'addCookie' method calls

    Examine cookie configuration parameters for secure flag settings

    Report a vulnerability if a cookie is configured without explicitly setting the secure flag to true

    Focus on response cookie configurations in Kotlin web applications

Vulnerable code example

public class CookieExample {
    public void setInsecureCookie(String value, HttpServletResponse response) {
        Cookie cookie = new Cookie("sessionId", value);  // Vulnerable: Missing secure and httpOnly flags
        response.addCookie(cookie);
    }

    public void explicitlyInsecureCookie(String value, HttpServletResponse response) {
        Cookie cookie = new Cookie("sessionId", value);...

✅ Secure code example

public class CookieExample {
    public void setSecureCookie(String value, HttpServletResponse response) {
        Cookie cookie = new Cookie("sessionId", value);
        cookie.setSecure(true);     // Ensure cookie is only sent over HTTPS
        cookie.setHttpOnly(true);    // Prevent XSS access to cookie
        response.addCookie(cookie);
    }
...