Changeset 5589 in subversion


Ignore:
Timestamp:
Dec 9, 2011 8:33:58 PM (18 months ago)
Author:
thomasb
Message:

Better CSS url() validation

Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r5564 r5589  
    22=========================== 
    33 
     4- Make Roundcube render the Email Standards Project Acid Test correctly 
    45- Deprecate $DB, $USER, $IMAP global variables, Use $RCMAIL instead 
    56- Add option to set default font for HTML message (#1484137) 
  • trunk/roundcubemail/program/include/main.inc

    r5586 r5589  
    892892  $source = rcmail_xss_entity_decode($source); 
    893893  $stripped = preg_replace('/[^a-z\(:;]/i', '', $source); 
    894   $evilexpr = 'expression|behavior' . (!$allow_remote ? '|url\(|import[^a]' : ''); 
    895   if (preg_match("/$evilexpr/i", $stripped) // don't accept No-Gos 
    896       || (strpos($stripped, 'url(') && !preg_match('!url\s*\([ "\'](https?:)//[a-z0-9/._+-]+["\' ]\)!Ui', $source))) // only allow clean urls 
     894  $evilexpr = 'expression|behavior|javascript:|import[^a]' . (!$allow_remote ? '|url\(' : ''); 
     895  if (preg_match("/$evilexpr/i", $stripped)) 
    897896    return '/* evil! */'; 
    898897 
    899898  // cut out all contents between { and } 
    900   while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) 
    901   { 
    902     $key = $replacements->add(substr($source, $pos+1, $pos2-($pos+1))); 
     899  while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) { 
     900    $styles = substr($source, $pos+1, $pos2-($pos+1)); 
     901 
     902    // check every line of a style block... 
     903    if ($allow_remote) { 
     904      $a_styles = preg_split('/;[\r\n]*/', $styles, -1, PREG_SPLIT_NO_EMPTY); 
     905      foreach ($a_styles as $line) { 
     906        $stripped = preg_replace('/[^a-z\(:;]/i', '', $line); 
     907        // ... and only allow strict url() values 
     908        if (stripos($stripped, 'url(') && !preg_match('!url\s*\([ "\'](https?:)//[a-z0-9/._+-]+["\' ]\)!Uims', $line)) { 
     909          $a_styles = array('/* evil! */'); 
     910          break; 
     911        } 
     912      } 
     913      $styles = join(";\n", $a_styles); 
     914    } 
     915 
     916    $key = $replacements->add($styles); 
    903917    $source = substr($source, 0, $pos+1) . $replacements->get_replacement($key) . substr($source, $pos2, strlen($source)-$pos2); 
    904918    $last_pos = $pos+2; 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r5588 r5589  
    835835 
    836836      // now check for evil strings like expression, behavior or url() 
    837       if (!preg_match('/expression|behavior/i', $stripped)) { 
    838         if (!$washtml->get_config('allow_remote') && preg_match('/url\(|import[^a]/i', $stripped)) 
     837      if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) { 
     838        if (!$washtml->get_config('allow_remote') && stripos($stripped, 'url(')) 
    839839          $washtml->extlinks = true; 
    840840        else 
Note: See TracChangeset for help on using the changeset viewer.