Skip to content

Commit

Permalink
Merge pull request bcit-ci#1560 from vlakoff/regex
Browse files Browse the repository at this point in the history
Clean up regexes in Security->xss_clean()
  • Loading branch information
narfbg committed Jul 2, 2012
2 parents 5211c09 + a81f60c commit 0692a1e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions system/core/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,20 @@ public function xss_clean($str, $is_image = FALSE)

if (preg_match('/<a/i', $str))
{
$str = preg_replace_callback('#<a\s+([^>]*?)(>|$)#si', array($this, '_js_link_removal'), $str);
$str = preg_replace_callback('#<a\s+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str);
}

if (preg_match('/<img/i', $str))
{
$str = preg_replace_callback('#<img\s+([^>]*?)(\s?/?>|$)#si', array($this, '_js_img_removal'), $str);
$str = preg_replace_callback('#<img\s+([^>]*?)(?:\s?/?>|$)#si', array($this, '_js_img_removal'), $str);
}

if (preg_match('/(script|xss)/i', $str))
if (preg_match('/script|xss/i', $str))
{
$str = preg_replace('#<(/*)(script|xss)(.*?)\>#si', '[removed]', $str);
$str = preg_replace('#</*(?:script|xss).*?>#si', '[removed]', $str);
}
}
while($original !== $str);
while ($original !== $str);

unset($original);

Expand Down Expand Up @@ -683,7 +683,7 @@ protected function _sanitize_naughty_html($matches)
protected function _js_link_removal($match)
{
return str_replace($match[1],
preg_replace('#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si',
preg_replace('#href=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
Expand All @@ -706,7 +706,7 @@ protected function _js_link_removal($match)
protected function _js_img_removal($match)
{
return str_replace($match[1],
preg_replace('#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
preg_replace('#src=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
Expand Down

0 comments on commit 0692a1e

Please sign in to comment.