From 74a61d559f6270fd98c1ec0003db65e33a297b98 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Mar 2021 15:38:10 +0100 Subject: [PATCH] FIX sanitizing with GETPOST(alphanohtml) #yogosha5629 --- htdocs/core/lib/functions.lib.php | 5 +++-- test/phpunit/SecurityTest.php | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4fc283b8082..e6547c8c5f1 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6167,12 +6167,13 @@ function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = if ($strip_tags) { $temp = strip_tags($temp); } else { + $temp = str_replace('<>', '', $temp); // No reason to have this into a text, except if value is to try bypass the next html cleaning $pattern = "/<[^<>]+>/"; // Example of $temp: 0000-021 $temp = preg_replace($pattern, "", $temp); // pass 1 - $temp after pass 1: 0000-021 $temp = preg_replace($pattern, "", $temp); // pass 2 - $temp after pass 2: 0000-021 - // Remove '<' into remainging, so non closing html tags like 'objnotdefined\''; $_POST["param11"]=' Name '; @@ -411,6 +412,10 @@ class SecurityTest extends PHPUnit\Framework\TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals($_POST['param8e'], $result, 'Test a string with non closing html tag with alphanohtml'); + $result=GETPOST("param8f", 'alphanohtml'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('abcsvg animate onbegin=alert(document.domain) a', $result, 'Test a string with html tag open with several <'); + $result=GETPOST("param9", 'alphanohtml'); print __METHOD__." result=".$result."\n"; $this->assertEquals($_POST["param9"], $result);