您的位置:首页 > 其它

会话标识未更新 漏洞处理

2016-11-14 20:20 1156 查看
如果是页面,可以在页面请求之前这么处理下:

HttpSession session=request.getSession();

session.invalidate();
Cookie[] cookies=request.getCookies();
if(null!=cookies){
   for(int i=0;i<cookies.length;i++){
       if(("JSESSIONID").equalsIgnoreCase(cookies[i].getName())){
           cookies[i].setMaxAge(0);
           response.addCookie(cookies[i]);
       }
   }
}
session = request.getSession(true);

如果是spring-security

在登录入口处,这么处理一下

changeNewSession(request);//更换session,处理会话表示未更新的漏洞

private void changeNewSession(HttpServletRequest request){
if (request.getSession() != null) {  
       //--------复制 session到临时变量  
       HttpSession session = request.getSession();  
       HashMap<String,Object> old = new HashMap<String,Object>();  
       Enumeration keys = (Enumeration) session.getAttributeNames();  

       while (keys.hasMoreElements()){  
           String key = (String) keys.nextElement();  
           old.put(key, session.getAttribute(key));  
           session.removeAttribute(key);  
       }  
       session.invalidate();  
       session=request.getSession(true);
         
       //-----------------复制session  
       for (Iterator it = old.entrySet().iterator(); it.hasNext();) {  
           Map.Entry entry = (Entry) it.next();  
           session.setAttribute((String) entry.getKey(), entry.getValue());  
       }  
   }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: