From dade48165874dc735013d918e8430e4c437b669e Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 5 May 2017 11:51:23 +0200 Subject: [PATCH] Fix bug where comment notation within style tag would cause the whole style to be ignored (#5747) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_utils.php | 1 + tests/Framework/Utils.php | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 222cfbb4f44..c0fb2d364ee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ CHANGELOG Roundcube Webmail - Fix bug where invalid recipients could be silently discarded (#5739) - Fix conflict with _gid cookie of Google Analytics (#5748) - Print error from CLI scripts when system/exec function is disabled (#5744) +- Fix bug where comment notation within style tag would cause the whole style to be ignored (#5747) RELEASE 1.3-rc -------------- diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 4bb83b12094..4aaaf40f2cf 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -489,6 +489,7 @@ public static function xss_entity_decode($content) $callback = function($matches) { return chr(hexdec($matches[1])); }; $out = html_entity_decode(html_entity_decode($content)); + $out = trim(preg_replace('/(^$)/', '', trim($out))); $out = preg_replace_callback('/\\\([0-9a-f]{4})/i', $callback, $out); $out = preg_replace('#/\*.*\*/#Ums', '', $out); $out = strip_tags($out); diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index ad81f64049c..71e9f3e30fb 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -227,6 +227,10 @@ function test_xss_entity_decode() $mod = rcube_utils::xss_entity_decode('#foo:after{content:"\003Cimg/src=x onerror=alert(2)>";}'); $this->assertNotContains(''); + $this->assertContains('#foo', $mod, "Strip HTML comments from content, but not the content"); } /**