我的ASP网站被注入iframe,请问如何写过滤代码?最好能给个例子!

来源:百度知道 编辑:UC知道 时间:2024/06/12 10:46:36
我的ASP网站被注入iframe,请问如何写过滤代码?最好能给个例子!

过滤script 过滤iframe 过滤on事件
public static String wipeScript(String html) {
String regex1 = "<script[\\s\\S]+</script *>";
String regex2 = " href *= *[\\s\\S]*script *:";
String regex3 = " on[\\s\\S]*=";
String regex4 = "<iframe[\\s\\S]+</iframe *>";
String regex5 = "<frameset[\\s\\S]+</frameset *>";
Pattern pat = Pattern.compile(regex1 + "|" + regex2 + "|" + regex3
+ "|" + regex4 + "|" + regex5, Pattern.CASE_INSENSITIVE);
Matcher m = pat.matcher(html);
html = m.replaceAll("");

html = html.replaceAll(regex2, ""); // 过滤href=javascript: (<A>) 属性
html = h