mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Merge pull request #14360 from ATM-Consulting/FIX_12.0_dol_string_onlythesehtmltags_remove_class_by_default
FIX 12.0 - dol_string_onlythesehtmltags(): remove class attribute by default
This commit is contained in:
@@ -5507,12 +5507,13 @@ function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
|
||||
* Clean a string to keep only desirable HTML tags.
|
||||
*
|
||||
* @param string $stringtoclean String to clean
|
||||
* @param string $cleanalsosomestyles Clean also some tags
|
||||
* @param boolean $cleanalsosomestyles Remove absolute/fixed positioning from inline styles
|
||||
* @param boolean $removeclassattribute Remove the class attribute from tags
|
||||
* @return string String cleaned
|
||||
*
|
||||
* @see dol_escape_htmltag() strip_tags() dol_string_nohtmltag() dol_string_neverthesehtmltags()
|
||||
*/
|
||||
function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1)
|
||||
function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1)
|
||||
{
|
||||
$allowed_tags = array(
|
||||
"html", "head", "meta", "body", "article", "a", "abbr", "b", "blockquote", "br", "cite", "div", "dl", "dd", "dt", "em", "font", "img", "ins", "hr", "i", "li", "link",
|
||||
@@ -5524,7 +5525,10 @@ function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1)
|
||||
$allowed_tags_string = '<'.$allowed_tags_string.'>';
|
||||
|
||||
if ($cleanalsosomestyles) {
|
||||
$stringtoclean = preg_replace('/position\s*:\s*(absolute|fixed)\s*!\s*important/', '', $stringtoclean); // Note: If hacker try to introduce css comment into string to bypass this regex, the string must also be encoded by the dol_htmlentitiesbr during output so it become harmless
|
||||
$stringtoclean = preg_replace('/position\s*:\s*(absolute|fixed)\s*!\s*important/i', '', $stringtoclean); // Note: If hacker try to introduce css comment into string to bypass this regex, the string must also be encoded by the dol_htmlentitiesbr during output so it become harmless
|
||||
}
|
||||
if ($removeclassattribute) {
|
||||
$stringtoclean = preg_replace('/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i', '\\1', $stringtoclean);
|
||||
}
|
||||
|
||||
$temp = strip_tags($stringtoclean, $allowed_tags_string);
|
||||
|
||||
Reference in New Issue
Block a user