diff --git a/CHANGELOG b/CHANGELOG index e591a2575..95fb4aec3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,6 +49,7 @@ CHANGELOG Roundcube Webmail - Fix wording of "Mark previewed messages as read" to "Mark messages as read" (#5952) - Enigma: Fix decryption of messages encoded with non-ascii charset (#5962) - Fix missing cursor in HTML editor on mail reply (#5969) +- Fix (again) bug where image data URIs in css style were treated as evil/remote in mail preview (#5580) RELEASE 1.3.1 ------------- diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 8586e6405..679e2924c 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -407,10 +407,17 @@ class rcube_utils if ($allow_remote) { $a_styles = preg_split('/;[\r\n]*/', $styles, -1, PREG_SPLIT_NO_EMPTY); - foreach ($a_styles as $line) { + for ($i=0, $len=count($a_styles); $i < $len; $i++) { + $line = $a_styles[$i]; $stripped = preg_replace('/[^a-z\(:;]/i', '', $line); - // ... and only allow strict url() values - if (stripos($stripped, 'url(') && !preg_match($strict_url_regexp, $line)) { + + // allow data:image uri, join with continuation + if (stripos($stripped, 'url(data:image')) { + $a_styles[$i] .= ';' . $a_styles[$i+1]; + unset($a_styles[$i+1]); + } + // allow strict url() values only + else if (stripos($stripped, 'url(') && !preg_match($strict_url_regexp, $line)) { $a_styles = array('/* evil! */'); break; } diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index 9b71acef5..2a5c090d9 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -218,7 +218,9 @@ class Framework_Utils extends PHPUnit_Framework_TestCase // allow data URIs with images (#5580) $mod = rcube_utils::mod_css_styles("body { background-image: url(data:image/png;base64,123); }", 'rcmbody'); - $this->assertEquals("#rcmbody { background-image: url(data:image/png;base64,123); }", $mod, "Data URIs in url() allowed"); + $this->assertContains("#rcmbody { background-image: url(data:image/png;base64,123);", $mod, "Data URIs in url() allowed [1]"); + $mod = rcube_utils::mod_css_styles("body { background-image: url(data:image/png;base64,123); }", 'rcmbody', true); + $this->assertContains("#rcmbody { background-image: url(data:image/png;base64,123);", $mod, "Data URIs in url() allowed [2]"); } function test_xss_entity_decode()