Insecure cookie settings can lead to unencrypted cookie transmission. Even if a cookie doesn't contain sensitive data now, sensitive data could be added later. It's good practice to transmit all cookies only through secure channels.
1def nonCompliant(res: HttpServletResponse): Unit = {
2 val cookie = new Cookie("key", "value")
3 cookie.setSecure(true)
4 cookie.setHttpOnly(true)
5 // Noncompliant: MaxAge set to one year.
6 cookie.setMaxAge(31536000)
7 res.addCookie(cookie)
8}
1def compliant(res: HttpServletResponse): Unit = {
2 val cookie = new Cookie("key", "value")
3 cookie.setSecure(true)
4 cookie.setHttpOnly(true)
5 // Compliant: MaxAge set to one week.
6 cookie.setMaxAge(604800)
7 res.addCookie(cookie)
8}