Skip to content

Instantly share code, notes, and snippets.

@syhily
Last active October 14, 2015 16:12
Show Gist options
  • Save syhily/160a57f6e0d43b348278 to your computer and use it in GitHub Desktop.
Save syhily/160a57f6e0d43b348278 to your computer and use it in GitHub Desktop.
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
/**
* 类名称:WebUtils <br>
* 类描述: <br>
*
* @author yufan.sheng
* @since 2014-4-27 上午10:11:49
* @version 1.0.0
*/
public class WebUtils {
public static String cleanXSS(String value) {
if (StringUtils.isBlank(value)) {
return value;
}
// You'll need to remove the spaces from the html entities below
value = value.trim().replaceAll("<", "&lt;").replaceAll(">", "&gt;");
// 定时组件,当参数的方法名
// value = value.replaceAll("\\(", "&#40;").replaceAll("\\)", "&#41;");
value = value.replaceAll("'", "&#39;");
value = value.replaceAll("eval\\((.*)\\)", "");
value = value.replaceAll("[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']",
"\"\"");
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment