I have my function here to clean strings called
function clean($str) {
$str = htmlspecialchars(strip_tags(trim(mb_convert_encoding($str, 'UTF-8', 'UTF-8'))), ENT_QUOTES, 'UTF-8');
return $str;
}
Right now, I checked the possible XSS attacks, And this one worked ok on <img src"$str">
but when i swapped the the element to <iframe src"$str">
the JS
was executed using the following
$attr = clean("javascript:alert(\"RSnake says, 'XSS'\")");
$str = "<iframe src=\"$attr\">";
But for $str = "<img src=\"$attr\">";
it was safe.
How to handle this vulnerability?
What i did was adding extra part for the function which was like this
function clean($str) {
$str = htmlspecialchars(strip_tags(trim(mb_convert_encoding($str, 'UTF-8', 'UTF-8'))), ENT_QUOTES, 'UTF-8');
$str = htmlentities($str, ENT_QUOTES);
return $str;
}