( ), , html (http://htmlpurifier.org) .
- XSS , XSS , , SAFE:
<?
$str = '
asd
<a STyLE="asd; expression" hRef=" javascript:" onx="asd">asd</a>
asd
<code><a href="javascript:">asd</a></code>
<scr<script></script>ipt ... >asd</script>
<a style="hey:good boy;" href="javascript:">asd</a>';
function stripteaser($str, $StripHTMLTags = true, $AllowableTags = NULL) {
$str = explode('<code>', $str);
$codes = array();
if (count($str) > 1) {
foreach ($str as $idx => $val) {
$val = explode('</code>', $val);
if (count($val) > 1) {
$uid = md5(uniqid(mt_rand(), true));
$codes[$uid] = htmlentities(array_shift($val), ENT_QUOTES, 'UTF-8');
$str[$idx] = "##$uid##" . implode('', $val);
}
}
}
$str = implode('', $str);
while (stripos($str, '<script') !== false) {
$str = str_ireplace('<script', '<script', $str);
}
$rptjob = function(&$str, $regexp) {
while (preg_match($regexp, $str, $matches)) {
$str = str_ireplace($matches[0], htmlentities($matches[0], ENT_QUOTES, 'UTF-8'), $str);
}
};
$rptjob($str, '/href[\s\n\t]*=[\s\n\t]*[\"\'][\s\n\t]*(javascript:|data:)/i');
$rptjob($str, '/style[\s\n\t]*=[\s\n\t]*[\"][^\"]*expression/i');
$rptjob($str, '/style[\s\n\t]*=[\s\n\t]*[\'][^\']*expression/i');
$rptjob($str, '/style[\s\n\t]*=[\s\n\t]*[\"][^\"]*behavior/i');
$rptjob($str, '/style[\s\n\t]*=[\s\n\t]*[\'][^\']*behavior/i');
$rptjob($str, '/on\w+[\s\n\t]*=[\s\n\t]*[\"\']/i');
if ($StripHTMLTags)
$str = strip_tags($str, $AllowableTags);
foreach ($codes as $idx => $code) {
$str = str_replace("##$idx##", $code, $str);
}
return $str;
}
echo stripteaser($str);
exit;
?>
: D
... ( ), , , html .
:
asd
<a STyLE="asd; expression" hRef=" javascript:" onx="asd">asd</a>
asd
<a href="javascript:">asd</a>
<scri<script></script>pt ... >asd</script>
<a style="hey:good boy;" href="javascript:">asd</a>
css, , JS VML IE , .
.
, -
;)