csrf漏洞怎么修复 csrf漏洞修复方案

主机教程 建站分享 2年前 (2022-11-16) 200次浏览

文章摘要:csrf漏洞怎么修复 csrf漏洞修复方案

使用Java对csrf漏洞进行修复,具体方法如下: package referer; import java. […]

使用Java对csrf漏洞进行修复,具体方法如下:

package referer;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class RefererServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setCharacterEncoding("UTF-8");

response.setContentType("text/html;charset=UTF-8");

String header = request.getHeader("Referer");

//String domainName = null;

String[] domain = { "localhost", "test.localhost", "admin.localhost" };

boolean key=false;

for (int i = 0; i < domain.length; i++) {

if (header != null && header.startsWith("http://" + domain[i]) && header.endsWith(domain[i])) {

key=true;

}

}

if(key==true) {

response.getWriter().write("成功读到打到数据");

}else{

response.getWriter().write("非法请求");

}

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

}


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

喜欢 (0)