解決方法: Cookies Hashing:每一個表單請求中都加入隨機的Cookie,由於網站中存在XSS漏洞而被偷竊的危險。
在Jsp文件頭引入
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
在登錄的jsp中添加
<% //增加隨機數,解決 CSRF 漏洞 String uuid = UUID.randomUUID().toString().replaceAll("-", ""); request.getSession().setAttribute("randTxt",uuid); //設置cookie只讀 String sessionid = request.getSession().getId(); response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; secure ; HttpOnly"); %>
form表單中添加一個隱藏域:Input
<input type="hidden" name="randSesion" value = "<%=request.getSession().getAttribute("randTxt")%>" />