阅读文本大概需要5分钟。
0x01:会话cookie中缺少HttpOnly属性
解决方案:向所有会话cookie 添加HttpOnly属性 ,可以在过滤器中统一添加。
HttpServletResponse resp = (HttpServletResponse)response; //httponly是微软对cookie做的扩展,该值指定 Cookie 是否可通过客户端脚本访问, //解决用户的cookie可能被盗用的问题,减少跨站脚本攻击 resp .setHeader( "Set-Cookie", "name=value; HttpOnly");0x02:跨站点请求伪造
解决方案:识别恶意请求,并有效拒绝这些恶意请求。例如在过滤器统一拦截跨站请求,并直接返回。
HttpServletRequest req = (HttpServletRequest)request; String referer = req .getHeader("Referer"); //REFRESH if(referer!=null && referer.indexOf(basePath)<0){ req .getRequestDispatcher(req .getRequestURI()).forward(request, response); }0x03:允许浏览器记住密码,可能导致密码信息泄露(Autocomplete HTML Attribute Not Disabled for Password Field )
解决方案:在密码输入框(type="password")设置为不自动填充
密 码:<input name="userinfo.userPwd" type="password" autocomplete = "off"/>0x04:HTML 注释敏感信息泄露
解决方案:删除注释信息。这个漏洞对于那些解析型语言也需要注意,像PHP。
0x05:允许SSL页面使用缓存,可能导致敏感数据泄露(Cacheable SSL Page Found)
解决方案:SSL页面禁用缓存
<meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Cache-Control" content="no-store" /> <meta http-equiv="Expires" content="0" />0x06:跨站点脚本编制、SQL 盲注
解决方案:过滤掉用户输入中的危险字符 ,使用统一拦截器,过滤用户脚本数据。
private String filterDangerString(String value) { if (value == null) { return null; } value = value.replaceAll("\\|", ""); value = value.replaceAll("&", "&"); value = value.replaceAll(";", ""); value = value.replaceAll("@", ""); value = value.replaceAll("'", ""); value = value.replaceAll("\"", ""); value = value.replaceAll("\\'", ""); value = value.replaceAll("\\\"", ""); value = value.replaceAll("<", "<"); value = value.replaceAll(">", ">"); value = value.replaceAll("\\(", ""); value = value.replaceAll("\\)", ""); value = value.replaceAll("\\+", ""); value = value.replaceAll("\r", ""); value = value.replaceAll("\n", ""); value = value.replaceAll("script", ""); value = value.replaceAll("'", ""); value = value.replaceAll(""", ""); value = value.replaceAll(">", ""); value = value.replaceAll("<", ""); value = value.replaceAll("=", ""); value = value.replaceAll("/", ""); return value; }0x07:会话标识未更新
解决方案:始终生成新的会话,供用户成功认证时登录;防止用户操纵会话标识。请勿接受用户浏览器登录时所提供的会话标识。
在登录验证成功之后调用下面方法
@SuppressWarnings("unchecked") private void createNewSession(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession oldSession = request.getSession(); // get the content of old session. Enumeration<String> attributeNames = oldSession.getAttributeNames(); Map<String, Object> attributeMap = new HashMap<String, Object>(); while(attributeNames != null && attributeNames.hasMoreElements()){ String attributeName = attributeNames.nextElement(); attributeMap.put(attributeName, oldSession.getAttribute(attributeName)); } oldSession.invalidate(); HttpSession newSession = request.getSession(true); // put the content into the new session. for (String key : attributeMap.keySet()) { newSession.setAttribute(key, attributeMap.get(key)); } }0x08:使用了Get方式传参,可能导致数据泄露(Query Parameter in SSL Request)
解决方案:尽量使用post方式传参
0x09:不充分账户封锁
解决方案:通过配置用户锁定不能登录,主要就是在登陆接口控制用户的恶意登陆。例如,如果用户输错密码多少次,就锁定用户。
0x10:登录错误消息凭证枚举
解决方案:每次登录失败的错误信息都一样,比如用户名或者密码错误,通过这样的提示进行处理解决即可;不需要明确告诉用户到时是用户名错误还是密码错误。
☆
往期精彩
☆
01
02
03
04
05
关注我
每天进步一点点
很干!在看吗? ☟