From b8aa7e2511fc450f3782ae6c3e210fbfdf09cd5b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 9 Sep 2024 15:56:47 +0200 Subject: [PATCH] Fix option restricthtmlallowlinkscript of GETPOST --- htdocs/core/lib/functions.lib.php | 10 ++++---- htdocs/website/index.php | 2 +- test/phpunit/SecurityTest.php | 42 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 1584500188b..156d6f29b0d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8333,7 +8333,9 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' } } - if (!empty($out) && getDolGlobalString('MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && $check != 'restricthtmlallowunvalid') { + if (!empty($out) && getDolGlobalString('MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array('restricthtmlallowunvalid', 'restricthtmlallowlinkscript'))) { + // Tidy can't be used for restricthtmlallowunvalid and restricthtmlallowlinkscript + // TODO Try to implement a hack for restricthtmlallowlinkscript by renaming tag and + '; + $result = dol_htmlwithnojs($s, 1, 'restricthtmlallowlinkscript'); + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = $sav1; + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = $sav2; + print __METHOD__." result=".$result."\n"; + $this->assertEquals($s, $result, 'Test for restricthtmlallowlinkscript'); + + // For a string with js and link with restricthtmlallowlinkscript + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0; + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1; + $s=' + + + '; + $result = dol_htmlwithnojs($s, 1, 'restricthtmlallowlinkscript'); + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = $sav1; + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = $sav2; + print __METHOD__." result=".$result."\n"; + $this->assertEquals($s, $result, 'Test for restricthtmlallowlinkscript'); + + // For a string with js and link with restricthtmlallowlinkscript + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 1; + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 0; + $s=' + + + '; + $result = dol_htmlwithnojs($s, 1, 'restricthtmlallowlinkscript'); + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = $sav1; + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = $sav2; + print __METHOD__." result=".$result."\n"; + $this->assertEquals($s, $result, 'Test for restricthtmlallowlinkscript'); + return 0; }