Kib*szott jó ez a PHP, mindenre van egyszerü megoldás...
Ha mást is érdekel akkor ez a megoldás:
PHP kód:
<?php
function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){
$string = strip_tags($string,$allowtags);
if (!is_null($allowattributes)) {
if(!is_array($allowattributes))
$allowattributes = explode(",",$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(")(?<!",$allowattributes);
if (strlen($allowattributes) > 0)
$allowattributes = "(?<!".$allowattributes.")";
$string = preg_replace_callback("/<[^>]*>/i",create_function(
'$matches',
'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'
),$string);
}
return $string;
}
?>
Használat:
PHP kód:
<?php strip_tags_attributes($string,'<strong><em><a>','href,rel'); ?>
És itt van egy lista a legáltalánosabb XSS szövegekről amiket érdemes ellenörizni:
hxxp://ha.ckers.org/xss.html
Könyvjelzők