diff --git a/includes/pbboardCodeparse.class.php b/includes/pbboardCodeparse.class.php
index 650b6aa..abb0e2e 100644
--- a/includes/pbboardCodeparse.class.php
+++ b/includes/pbboardCodeparse.class.php
@@ -637,7 +637,7 @@ function censor_words($text)
$text = str_ireplace('rel="nofollow" href="#', 'href="#', $text);
$text = str_ireplace('rel="dofollow" href="#', 'href="#', $text);
eval($PowerBB->functions->get_fetch_hooks('BBCodeParseHooks3'));
-
+ // $text = strip_tags($text);
$censorwords = preg_split('#[ \r\n\t]+#', $PowerBB->_CONF['info_row']['censorwords'], -1, PREG_SPLIT_NO_EMPTY);
$text = str_ireplace($censorwords,'**', $text);
$blankasciistrip ="160 173 u8205 u8204 u8237 u8238";
@@ -760,7 +760,8 @@ function censor_words($text)
$text = str_replace(' rel="dofollow" ', ' rel="dofollow" ', $text);
$text = str_replace("
", "
", $text);
-
+ //XSS filtering function
+ $text = $this->xss_clean($text);
eval($PowerBB->functions->get_fetch_hooks('BBCodeParseHooks_cr'));
@@ -818,6 +819,44 @@ function censor_words($text)
return $this->replace($text."n-l-2-b-r");
}
+
+ //XSS filtering function
+ function xss_clean($data)
+ {
+ // Fix &entity\n;
+ $data = str_replace(array('&','<','>'), array('&','<','>'), $data);
+ $data = preg_replace('/(*\w+)[\x00-\x20]+;/u', '$1;', $data);
+ $data = preg_replace('/(*[0-9A-F]+);*/iu', '$1;', $data);
+ $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
+
+ // Remove any attribute starting with "on" or xmlns
+ $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
+
+ // Remove javascript: and vbscript: protocols
+ $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
+ $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
+ $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
+
+ // Only works in IE:
+ $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
+ $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
+ $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
+
+ // Remove namespaced elements (we do not need them)
+ $data = preg_replace('#*\w+:\w[^>]*+>#i', '', $data);
+
+ do
+ {
+ // Remove really unwanted tags
+ $old_data = $data;
+ $data = preg_replace('#*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
+ }
+ while ($old_data !== $data);
+
+ // we are done...
+ return $data;
+ }
+
// long URL, Shortening Long URLs With PHP
function shortenurl($Aurl,$Burl,$lg_max)
{
@@ -1553,7 +1592,6 @@ function replace_htmlentities($string)
$string = preg_replace_callback($li_not, function($lidd) {
return $this->li_not_bar($lidd[1]);
}, $string);
-
return $string;
}