note 83022 deleted from function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 15:53:41 +0000 |
| Subject: | note 83022 deleted from function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154709@lists.php.net to get a copy of this message | ||
Note Submitter: Massoud Abbagash
----
There is still a flaw in your function.
Look at this, the [onmouseover] sample script below remains. Even after the treatment with the
function [strip_tags_attributes].
<?php
function strip_tags_attributes($sSource, $aAllowedTags = array(), $aDisabledAttributes =
array('onabort', 'onactivate', 'onafterprint',
'onafterupdate', 'onbeforeactivate', 'onbeforecopy',
'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus',
'onbeforepaste', 'onbeforeprint', 'onbeforeunload',
'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange',
'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect',
'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged',
'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag',
'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave',
'ondragover', 'ondragstart', 'ondrop', 'onerror',
'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus',
'onfocusin', 'onfocusout', 'onhelp', 'onkeydown',
'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload',
'onlosecapture', 'onmousedown', 'onmouseenter',
'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover',
'onmouseup', 'onmousewheel', 'onmove', 'onmoveend',
'onmovestart', 'onpaste', 'onpropertychange',
'onreadystatechange', 'onreset', 'onresize', 'onresizeend',
'onresizestart', 'onrowexit', 'onrowsdelete',
'onrowsinserted', 'onscroll', 'onselect',
'onselectionchange', 'onselectstart', 'onstart', 'onstop',
'onsubmit', 'onunload'))
{
if (empty($aDisabledAttributes)) return strip_tags($sSource, implode('',
$aAllowedTags));
return preg_replace('/<(.*?)>/ie', "'<' .
preg_replace(array('/javascript:[^\"\']*/i', '/(" .
implode('|', $aDisabledAttributes) . ")[ \\t\\n]*=[
\\t\\n]*[\"\'][^\"\']*[\"\']/i', '/\s+/'),
array('', '', ' '), stripslashes('\\1')) .
'>'", strip_tags($sSource, implode('', $aAllowedTags)));
}
$source="<big onmouseover=alert('Hello!')>Move your mouse here (this
doesn't work with [ strip_tags_attributes ])</big>";
$striped_source=strip_tags_attributes($source,array('<big>'));
echo($striped_source);
?>
Now,this is my correction:
<?php
function strip_tags_attributes($sSource, $aAllowedTags = array(), $aDisabledAttributes =
array('onabort', 'onactivate', 'onafterprint',
'onafterupdate', 'onbeforeactivate', 'onbeforecopy',
'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus',
'onbeforepaste', 'onbeforeprint', 'onbeforeunload',
'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange',
'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect',
'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged',
'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag',
'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave',
'ondragover', 'ondragstart', 'ondrop', 'onerror',
'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus',
'onfocusin', 'onfocusout', 'onhelp', 'onkeydown',
'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload',
'onlosecapture', 'onmousedown', 'onmouseenter',
'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover',
'onmouseup', 'onmousewheel', 'onmove', 'onmoveend',
'onmovestart', 'onpaste', 'onpropertychange',
'onreadystatechange', 'onreset', 'onresize', 'onresizeend',
'onresizestart', 'onrowexit', 'onrowsdelete',
'onrowsinserted', 'onscroll', 'onselect',
'onselectionchange', 'onselectstart', 'onstart', 'onstop',
'onsubmit', 'onunload'))
{
if (empty($aDisabledAttributes)) return strip_tags($sSource, implode('',
$aAllowedTags));
return preg_replace('/\s(' . implode('|', $aDisabledAttributes) .
').*?([\s\>])/', '\\2', preg_replace('/<(.*?)>/ie',
"'<' . preg_replace(array('/javascript:[^\"\']*/i',
'/(" . implode('|', $aDisabledAttributes) . ")[ \\t\\n]*=[
\\t\\n]*[\"\'][^\"\']*[\"\']/i', '/\s+/'),
array('', '', ' '), stripslashes('\\1')) .
'>'", strip_tags($sSource, implode('', $aAllowedTags))) );
}
$source="<big onmouseover=alert('Hello!')>Move your mouse here (this work with
[ strip_tags_attributes corrected ])</big>";
$striped_source=strip_tags_attributes($source,array('<big>'));
echo($striped_source);
?>