| | |
| | | */ |
| | | public List<String> excludes = new ArrayList<>(); |
| | | |
| | | /** |
| | | * xss过滤开关 |
| | | */ |
| | | public boolean enabled = false; |
| | | |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | String tempExcludes = filterConfig.getInitParameter("excludes"); |
| | | String tempEnabled = filterConfig.getInitParameter("enabled"); |
| | | if (StrUtil.isNotEmpty(tempExcludes)) |
| | | { |
| | | String[] url = tempExcludes.split(","); |
| | |
| | | { |
| | | excludes.add(url[i]); |
| | | } |
| | | } |
| | | if (StrUtil.isNotEmpty(tempEnabled)) |
| | | { |
| | | enabled = Boolean.valueOf(tempEnabled); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) |
| | | { |
| | | if (!enabled) |
| | | { |
| | | return true; |
| | | } |
| | | if (excludes == null || excludes.isEmpty()) |
| | | { |
| | | return false; |
| | | } |
| | | String url = request.getServletPath(); |
| | | for (String pattern : excludes) |
| | | { |
| | | Pattern p = Pattern.compile("^" + pattern); |
| | | Matcher m = p.matcher(url); |
| | | if (m.find()) |
| | | String method = request.getMethod(); |
| | | // GET DELETE 不过滤 |
| | | if (method == null || method.matches("GET") || method.matches("DELETE")) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | return StrUtil.matches(url, excludes); |
| | | } |
| | | |
| | | @Override |