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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php
// lib/ckeditor5/clean_html.php
function getAndCleanEditorOutput(): string
{
// bugs possibles sans trim() lorsqu'on insère le HTML dans l'éditeur
$html = trim($_POST["contenu"]);
// pour debugguer ou tester des paramètres avec htmlawed
//~ $nom_fichier = "avant.html";
//~ $fichier = fopen('data/' . $page . '/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu
//~ fputs($fichier, $html);
//~ fclose($fichier);
//~ chmod('data/' . $page . '/' . $nom_fichier, 0666);
// sécurisation du HTML (faille XSS)
require 'vendor/htmlawed/htmlawed/htmLawed.php';
$configHtmLawed = array(
'safe'=>1, // protection contre les élements et attributs dangereux
// balises autorisées
'elements'=>'h2, h3, h4, p, span, i, strong, u, s, mark, blockquote, li, ol, ul, a, figure, hr, img, figcaption, table, tbody, tr, td',
// note: change <s></s> en <span style="text-decoration: line-through;"></span>
// attributs interdits
'deny_attribute'=>'id', // 'class' et 'style' sont conservés pour le ckeditor
);
$specHtmLawed = ''; // optionnel: faire qu'un certain élément puisse n'avoir que certains attributs
$html = htmLawed($html, $configHtmLawed, $specHtmLawed);
//~ $nom_fichier = "après.html";
//~ $fichier = fopen('data/' . $page . '/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu
//~ fputs($fichier, $html);
//~ fclose($fichier);
//~ chmod('data/' . $page . '/' . $nom_fichier, 0666);
return $html;
}
|