From f3e54f37c6c18607929d071af708bfd2888efc67 Mon Sep 17 00:00:00 2001 From: Mike Little Date: Sat, 2 Aug 2003 13:26:26 +0000 Subject: [PATCH] Separated out html sanitise stuff from balance tags. Also made it slightly more robust. git-svn-id: https://develop.svn.wordpress.org/trunk@284 602fd350-edb4-49c9-b593-d223f7449a82 --- b2-include/b2functions.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/b2-include/b2functions.php b/b2-include/b2functions.php index 74dcedc144..558228c8af 100644 --- a/b2-include/b2functions.php +++ b/b2-include/b2functions.php @@ -1113,6 +1113,20 @@ function pingback($content, $post_ID) { debug_fclose($log); } +/** + ** sanitise HTML attributes, remove frame/applet/*script/mouseovers,etc. tags + ** so that this kind of thing cannot be done: + ** This is how we can do bad stuff! + **/ +function sanitise_html_attributes($text) { + $text = preg_replace('#( on[a-z]{1,}|style|class|id)="(.*?)"#i', '', $text); + $text = preg_replace('#( on[a-z]{1,}|style|class|id)=\'(.*?)\'#i', '', $text); + $text = preg_replace('#( on[a-z]{1,}|style|class|id)[ \t]*=[ \t]*([^ \t\>]*?)#i', '', $text); + $text = preg_replace('#([a-z]{1,})="(( |\t)*?)(javascript|vbscript|about):(.*?)"#i', '$1=""', $text); + $text = preg_replace('#([a-z]{1,})=\'(( |\t)*?)(javascript|vbscript|about):(.*?)\'#i', '$1=""', $text); + $text = preg_replace('#\<(\/{0,1})([a-z]{0,2})(frame|applet)(.*?)\>#i', '', $text); + return $text; +} /* balanceTags @@ -1132,19 +1146,11 @@ function pingback($content, $post_ID) { Added Cleaning Hooks 1.0 First Version */ - function balanceTags($text, $is_comment = 0) { global $use_balanceTags; if ($is_comment) { - $text = stripslashes($text); - // sanitise HTML attributes, remove frame/applet tags - $text = preg_replace('#( on[a-z]{1,}|style|class|id)="(.*?)"#i', '', $text); - $text = preg_replace('#( on[a-z]{1,}|style|class|id)=\'(.*?)\'#i', '', $text); - $text = preg_replace('#([a-z]{1,})="(( |\t)*?)(javascript|vbscript|about):(.*?)"#i', '$1=""', $text); - $text = preg_replace('#([a-z]{1,})=\'(( |\t)*?)(javascript|vbscript|about):(.*?)\'#i', '$1=""', $text); - $text = preg_replace('#\<(\/{0,1})([a-z]{0,2})(frame|applet)(.*?)\>#i', '', $text); - $text = addslashes($text); + $text = sanitise_html_attributes($text); } if ($use_balanceTags == 0) {