怎么修复反射型xss漏洞 反射型xss漏洞的修复建议

主机教程 建站分享 2年前 (2022-12-05) 189次浏览

文章摘要:怎么修复反射型xss漏洞 反射型xss漏洞的修复建议

通过在项目中自定义一个Filter过滤器实现修复反射型xss漏洞,具体方法如下: package com.ea […]

通过在项目中自定义一个Filter过滤器实现修复反射型xss漏洞,具体方法如下:

package com.eastrobot.robotdev.filter;

import javax.servlet.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

public class XssFilter implements Filter {

@Override

public void init(FilterConfig filterConfig) throws ServletException {

}

@Override

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

HttpServletRequest req = (HttpServletRequest) request;

HttpServletResponse resp = (HttpServletResponse) response;

// 解决动态脚本获取网页cookie,将cookie设置成HttpOnly

String sessionId = req.getSession().getId();

resp.setHeader("SET-COOKIE", "JSESSIONID=" + sessionId + "; HttpOnly");

resp.setHeader("x-frame-options", "SAMEORIGIN");

chain.doFilter(new XssHttpServletRequestWrapper((HttpServletRequest) request), response);

}

@Override

public void destroy() {

}

}


声明:
若非注明,本站文章源于互联网收集整理和网友分享发布,如有侵权,请联系站长处理。
文章名称:怎么修复反射型xss漏洞 反射型xss漏洞的修复建议
文章链接:http://www.7966.org/post/14889.html
转载请注明出处

喜欢 (0)