- Add support for data URI scheme [RFC2397] (#1486740)

release-0.6
alecpl 14 years ago
parent 2bb1f633fb
commit 0b7f3a8ab2

@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail CHANGELOG RoundCube Webmail
=========================== ===========================
- Add support for data URI scheme [RFC2397] (#1486740)
- Added 'actionbefore', 'actionafter', 'responsebefore', 'responseafter' events - Added 'actionbefore', 'actionafter', 'responsebefore', 'responseafter' events
- Removed response.callbacks feature - Removed response.callbacks feature
- Fix double-addition of e-mail domain to content ID in HTML images - Fix double-addition of e-mail domain to content ID in HTML images

@ -73,6 +73,7 @@
* Roundcube Changes: * Roundcube Changes:
* - added $block_elements * - added $block_elements
* - changed $ignore_elements behaviour * - changed $ignore_elements behaviour
* - added RFC2397 support
*/ */
class washtml class washtml
@ -131,31 +132,34 @@ class washtml
private function wash_style($style) { private function wash_style($style) {
$s = ''; $s = '';
foreach(explode(';', $style) as $declaration) { foreach (explode(';', $style) as $declaration) {
if(preg_match('/^\s*([a-z\-]+)\s*:\s*(.*)\s*$/i', $declaration, $match)) { if (preg_match('/^\s*([a-z\-]+)\s*:\s*(.*)\s*$/i', $declaration, $match)) {
$cssid = $match[1]; $cssid = $match[1];
$str = $match[2]; $str = $match[2];
$value = ''; $value = '';
while(sizeof($str) > 0 && while (sizeof($str) > 0 &&
preg_match('/^(url\(\s*[\'"]?([^\'"\)]*)[\'"]?\s*\)'./*1,2*/ preg_match('/^(url\(\s*[\'"]?([^\'"\)]*)[\'"]?\s*\)'./*1,2*/
'|rgb\(\s*[0-9]+\s*,\s*[0-9]+\s*,\s*[0-9]+\s*\)'. '|rgb\(\s*[0-9]+\s*,\s*[0-9]+\s*,\s*[0-9]+\s*\)'.
'|-?[0-9.]+\s*(em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)?'. '|-?[0-9.]+\s*(em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)?'.
'|#[0-9a-f]{3,6}|[a-z0-9\-]+'. '|#[0-9a-f]{3,6}|[a-z0-9\-]+'.
')\s*/i', $str, $match)) { ')\s*/i', $str, $match)) {
if($match[2]) { if ($match[2]) {
if($src = $this->config['cid_map'][$match[2]]) if ($src = $this->config['cid_map'][$match[2]])
$value .= ' url(\''.htmlspecialchars($src, ENT_QUOTES) . '\')'; $value .= ' url('.htmlspecialchars($src, ENT_QUOTES) . ')';
else if(preg_match('/^(http|https|ftp):.*$/i', $match[2], $url)) { else if (preg_match('/^(http|https|ftp):.*$/i', $match[2], $url)) {
if($this->config['allow_remote']) if ($this->config['allow_remote'])
$value .= ' url(\''.htmlspecialchars($url[0], ENT_QUOTES).'\')'; $value .= ' url('.htmlspecialchars($url[0], ENT_QUOTES).')';
else else
$this->extlinks = true; $this->extlinks = true;
} }
} else if($match[0] != 'url' && $match[0] != 'rbg')//whitelist ? else if (preg_match('/^data:.+/i', $url)) { // RFC2397
$value .= ' url('.htmlspecialchars($url, ENT_QUOTES).')';
}
} else if ($match[0] != 'url' && $match[0] != 'rbg') //whitelist ?
$value .= ' ' . $match[0]; $value .= ' ' . $match[0];
$str = substr($str, strlen($match[0])); $str = substr($str, strlen($match[0]));
} }
if($value) if ($value)
$s .= ($s?' ':'') . $cssid . ':' . $value . ';'; $s .= ($s?' ':'') . $cssid . ':' . $value . ';';
} }
} }
@ -167,20 +171,20 @@ class washtml
$t = ''; $t = '';
$washed; $washed;
foreach($node->attributes as $key => $plop) { foreach ($node->attributes as $key => $plop) {
$key = strtolower($key); $key = strtolower($key);
$value = $node->getAttribute($key); $value = $node->getAttribute($key);
if(isset($this->_html_attribs[$key]) || if (isset($this->_html_attribs[$key]) ||
($key == 'href' && preg_match('/^(http:|https:|ftp:|mailto:|#).+/i', $value))) ($key == 'href' && preg_match('/^(http:|https:|ftp:|mailto:|#).+/i', $value)))
$t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; $t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
else if($key == 'style' && ($style = $this->wash_style($value))) else if ($key == 'style' && ($style = $this->wash_style($value)))
$t .= ' style="' . $style . '"'; $t .= ' style="' . $style . '"';
else if($key == 'background' || ($key == 'src' && strtolower($node->tagName) == 'img')) { //check tagName anyway else if ($key == 'background' || ($key == 'src' && strtolower($node->tagName) == 'img')) { //check tagName anyway
if($src = $this->config['cid_map'][$value]) { if ($src = $this->config['cid_map'][$value]) {
$t .= ' ' . $key . '="' . htmlspecialchars($src, ENT_QUOTES) . '"'; $t .= ' ' . $key . '="' . htmlspecialchars($src, ENT_QUOTES) . '"';
} }
else if(preg_match('/^(http|https|ftp):.+/i', $value)) { else if (preg_match('/^(http|https|ftp):.+/i', $value)) {
if($this->config['allow_remote']) if ($this->config['allow_remote'])
$t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; $t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
else { else {
$this->extlinks = true; $this->extlinks = true;
@ -188,6 +192,9 @@ class washtml
$t .= ' ' . $key . '="' . htmlspecialchars($this->config['blocked_src'], ENT_QUOTES) . '"'; $t .= ' ' . $key . '="' . htmlspecialchars($this->config['blocked_src'], ENT_QUOTES) . '"';
} }
} }
else if (preg_match('/^data:.+/i', $value)) { // RFC2397
$t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
}
} else } else
$washed .= ($washed?' ':'') . $key; $washed .= ($washed?' ':'') . $key;
} }

Loading…
Cancel
Save