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.
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);
}
...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.