Prémunissez vous des attaques XSS
Posté : 13 janv. 2007, 23:37
Cherchant un moyen d'éviter les attaques XSS , j'ai trouvé un script très efficace nommé kses qui est très pratique et très simple.
Utilisation :
J'ai mis dans le tableau $allowed_tags tous les tags html que j'ai pu trouver utiles, si vous en avez d'autres, n'hésitez pas
N'oubliez pas d'inclure kses.php, disponible dans l'archive téléchargeable sur le site officiel.
Bonne soirée a tous
Utilisation :
$out = stripslashes($in);
$out = nl2br($out);
$allowed_tags = array('b' => array(),
'i' => array(),
'a' => array('href' => 1,
'title' => 1,
'name' => 1),
'p' => array('align' => 1,
'dummy' => array('valueless' => 'y')),
'img' => array('src' => 1),
'font' => array('size' => array('minval' => 4,
'maxval' => 20)),
'br' => array(),
'ul' => array('id' => 1,
'class' => 1),
'li' => array('id' => 1,
'class' => 1),
'div' => array('align' => 1,
'span' => 1,
'id' => 1),
'span' => array('span' => 1,
'id' => 1,
'style' => 1),
'font' => array('color' => 1,
'face' => 1,
'size' => 1),
'blockquote' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'sup' => array(),
'sub' => array(),
'strong' => array(),
'em' => array(),
'u' => array(),
'tr' => array(),
'td' => array(),
'strike' => array(),
'table' => array('width' => 1,
'height' => 1,
'style' => 1,
'summary' => 1,
'cellpadding' => 1,
'cellspacing' => 1,
'border' => 1,
'align' => 1,
'style' => 1,
'dir' => 1,
'id' => 1,
'lang' => 1));
/*
$out = parse_clean_marker('script', $out);
$out = parse_clean_marker('frame', $out);
$out = parse_clean_marker('iframe', $out);
*/
$out = kses($out, $allowed_tags, array('http', 'https', 'ftp'));
$in est le flux de base, et $out la sortie J'ai mis dans le tableau $allowed_tags tous les tags html que j'ai pu trouver utiles, si vous en avez d'autres, n'hésitez pas
N'oubliez pas d'inclure kses.php, disponible dans l'archive téléchargeable sur le site officiel.
Bonne soirée a tous