• JAVAWEB项目报"xxx响应头缺失“漏洞处理方案


    新增一个拦截器,在拦截器doFilter()方法增加以下代码

    public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
    		//增加响应头缺失代码
    		HttpServletRequest req=(HttpServletRequest)request;
    		HttpServletResponse res=(HttpServletResponse)response;
    		res.addHeader("X-Frame-Options","SAMEORIGIN");
    		res.addHeader("Referer-Policy","origin");
    		res.addHeader("Content-Security-Policy","object-src 'self'");
    		res.addHeader("X-Permitted-Cross-Domain-Policies","master-only");
    		res.addHeader("X-Content-Type-Options","nosniff");
    		res.addHeader("X-XSS-Protection","1; mode=block");
    		res.addHeader("X-Download-Options","noopen");
    
    		//处理cookie问题
    		Cookie[] cookies = req.getCookies();
    		if (cookies != null) {
    			for (Cookie cookie : cookies) {
    				String value = cookie.getValue();
    				StringBuilder builder = new StringBuilder();
    				builder.append(cookie.getName()+"="+value+";");
    				builder.append("Secure;");//Cookie设置Secure标识
    				builder.append("HttpOnly;");//Cookie设置HttpOnly
    				res.addHeader("Set-Cookie", builder.toString());
    			}
    
    		}
    
    			chain.doFilter(request, response);
    
    	}
    

      

  • 相关阅读:
    大一秋学期记录
    韦尼克区受损者如何说话
    暑假训练idea汇总
    高三树洞
    OI回忆录
    NOI2018游记
    收藏
    PKUSC2018游记
    CTSC/APIO2018游记
    Caused by: org.xml.sax.SAXParseException: 外部 DTD: 无法读取外部 DTD 'mybatis-generator-config_1_0.dtd'
  • 原文地址:https://www.cnblogs.com/pxblog/p/11630736.html
Copyright © 2020-2023  润新知