用Java解决“加密会话(ssl)cookie中缺少安全属性”

问题描述 投票:0回答:1

最近,IBM Security AppScan 发现加密会话 (ssl) cookie 中缺少安全属性的问题。报告如下:

enter image description here

这个应用程序是由Java编写的,我添加了一个过滤器来设置所有cookie的安全,代码:

public class BasicFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    Cookie[] cookies = req.getCookies();
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    if( cookies != null && cookies.length > 0) {
        for (int i = 0; i < cookies.length; i++) {
            cookies[i].setSecure(true);
            cookies[i].setHttpOnly(true);
            resp.addCookie(cookies[i]);
        }
    }
    filterChain.doFilter(req,resp);
}

@Override
public void destroy() {

}

}

它可以工作,而所有 cookie 都会像这样响应两次,并且它会尝试一遍又一遍地登录(使用 SSO 登录):

enter image description here

感谢您的好意帮助,我该如何启用安全并解决 cookie 问题,希望你们能给我一些解决这个问题的想法。 谢谢!

java security cookies bluemix-app-scan
1个回答
0
投票

IBM 支持论坛中也发布了同样的问题。您应该研究配置修复。请看这里

https://www.ibm.com/support/pages/1505-ifix-po05616-missing-secure-attribute-encrypted-session-ssl-cookie-and-missing-httponly-session-cookie

© www.soinside.com 2019 - 2024. All rights reserved.