summaryrefslogtreecommitdiff
path: root/controller/Security.php
blob: c53cdc6fa4c28fc5dea2a130df416860f5d105c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// controller/Security.php

// sécurité faille XSS avec htmLawed
require('lib/htmlawed/htmLawed.php');

class Security
{
	private static $configHtmLawed = array(
	    'safe'=>1, // protection contre les élements et attributs dangereux
	    'elements'=>'h2, h3, h4, p, br, span, i, strong, u, mark, blockquote, li, ol, ul, a, figure, hr, img, figcaption, table, tbody, tr, td', // paramètre optionnel: les balises non indiquées sont supprimées
	    'deny_attribute'=>'id', // gêner le JS hostile
	    // on garde 'class' et 'style' utilisés par le ckediteur
	);
	private static $specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs

	public static function secureString(string $chaine): string
	{
		$chaine = htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed);
	    $chaine = trim($chaine); // supprimer espaces, tabulations et sauts de ligne en début et fin de chaine (pour l'entrée de l'éditeur)
	    return $chaine;
	}
}

function removeSpacesTabsCRLF(string $chaine): string
{
	$cibles = [' ', "\t", "\n", "\r"]; // doubles quotes !!
	return(str_replace($cibles, '', $chaine));
}