Ignore:
Timestamp:
Dec 9, 2011 4:13:54 PM (18 months ago)
Author:
thomasb
Message:

Allow clean background:url(...) styles in safe mode. This will make Roundcube pass the Email Standards Acid Test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/main.inc

    r5562 r5586  
    884884 * @return string Modified CSS source 
    885885 */ 
    886 function rcmail_mod_css_styles($source, $container_id) 
     886function rcmail_mod_css_styles($source, $container_id, $allow_remote=false) 
    887887  { 
    888888  $last_pos = 0; 
     
    890890 
    891891  // ignore the whole block if evil styles are detected 
    892   $stripped = preg_replace('/[^a-z\(:;]/', '', rcmail_xss_entity_decode($source)); 
    893   if (preg_match('/expression|behavior|url\(|import[^a]/', $stripped)) 
     892  $source = rcmail_xss_entity_decode($source); 
     893  $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 
    894897    return '/* evil! */'; 
    895  
    896   // remove css comments (sometimes used for some ugly hacks) 
    897   $source = preg_replace('!/\*(.+)\*/!Ums', '', $source); 
    898898 
    899899  // cut out all contents between { and } 
     
    938938  $out = html_entity_decode(html_entity_decode($content)); 
    939939  $out = preg_replace_callback('/\\\([0-9a-f]{4})/i', 'rcmail_xss_entity_decode_callback', $out); 
    940   $out = preg_replace('#/\*.*\*/#Um', '', $out); 
     940  $out = preg_replace('#/\*.*\*/#Ums', '', $out); 
    941941  return $out; 
    942942} 
Note: See TracChangeset for help on using the changeset viewer.