当前位置: 代码迷 >> 综合 >> XSS攻击Filter
  详细解决方案

XSS攻击Filter

热度:27   发布时间:2023-09-05 17:55:26.0
private String stripXSS(String value) {if (value != null) {// NOTE: It‘s highly recommended to use the ESAPI library and uncomment the following line to// avoid encoded attacks.// value = ESAPI.encoder().canonicalize(value);// Avoid null charactersvalue = value.replaceAll("", "");// Avoid anything between script tagsPattern scriptPattern = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE);value = scriptPattern.matcher(value).replaceAll("");// Avoid anything in a src="..." type of e-xpressionscriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\‘(.*?)\\\‘", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);value = scriptPattern.matcher(value).replaceAll("");scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Patte
  相关解决方案