Changeset 2324 in subversion
- Timestamp:
- Mar 2, 2009 12:34:18 PM (4 years ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 4 edited
-
program/include/rcmail.php (modified) (1 diff)
-
program/steps/mail/func.inc (modified) (6 diffs)
-
tests/mailfunc.php (modified) (3 diffs)
-
tests/src/htmlxss.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/rcmail.php
r2237 r2324 48 48 * This implements the 'singleton' design pattern 49 49 * 50 * @return object qvertThe one and only instance50 * @return object rcmail The one and only instance 51 51 */ 52 52 static function get_instance() -
trunk/roundcubemail/program/steps/mail/func.inc
r2322 r2324 22 22 require_once('include/rcube_smtp.inc'); 23 23 24 $EMAIL_ADDRESS_PATTERN = ' /([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i';24 $EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})'; 25 25 26 26 // actions that do not require imap connection … … 708 708 709 709 $washer = new washtml($wash_opts); 710 $washer->add_callback('a', 'rcmail_washtml_callback');711 710 $washer->add_callback('form', 'rcmail_washtml_callback'); 712 711 … … 819 818 case 'form': 820 819 $out = html::div('form', $content); 821 break;822 823 case 'a':824 if ($attrib) $attrib .= ' target="_blank"';825 $out = '<a'.$attrib.'>' . $content . '</a>';826 820 break; 827 821 … … 1041 1035 1042 1036 // modify HTML links to open a new window if clicked 1043 $body = preg_replace('/<(a|link)\s+([^>]+)>/Uie', "rcmail_alter_html_link('\\1','\\2', '$container_id');", $body); 1037 $GLOBALS['rcmail_html_container_id'] = $container_id; 1038 $body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body); 1039 unset($GLOBALS['rcmail_html_container_id']); 1044 1040 1045 1041 // add comments arround html and other tags … … 1069 1065 * parse link attributes and set correct target 1070 1066 */ 1071 function rcmail_alter_html_link($ tag, $attrs, $container_id)1067 function rcmail_alter_html_link($matches) 1072 1068 { 1073 $attrib = parse_attrib_string($attrs); 1069 global $EMAIL_ADDRESS_PATTERN; 1070 1071 $tag = $matches[1]; 1072 $attrib = parse_attrib_string($matches[2]); 1074 1073 $end = '>'; 1075 1074 1076 1075 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { 1077 $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($ container_id);1076 $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($GLOBALS['rcmail_html_container_id']); 1078 1077 $end = ' />'; 1079 1078 } 1080 else if (stristr((string)$attrib['href'], 'mailto:')) { 1079 else if (preg_match("/^mailto:$EMAIL_ADDRESS_PATTERN/i", $attrib['href'], $mailto)) { 1080 $attrib['href'] = $mailto[0]; 1081 1081 $attrib['onclick'] = sprintf( 1082 1082 "return %s.command('compose','%s',this)", 1083 1083 JS_OBJECT_NAME, 1084 JQ( substr($attrib['href'], 7)));1084 JQ($mailto[1])); 1085 1085 } 1086 1086 else if (!empty($attrib['href']) && $attrib['href'][0] != '#') { … … 1113 1113 $out .= sprintf('%s <%s>', Q($part['name']), $part['mailto']); 1114 1114 } 1115 else if (preg_match( $EMAIL_ADDRESS_PATTERN, $part['mailto'])) {1115 else if (preg_match("/$EMAIL_ADDRESS_PATTERN/i", $part['mailto'])) { 1116 1116 if ($linked) { 1117 1117 $out .= html::a(array( -
trunk/roundcubemail/tests/mailfunc.php
r2323 r2324 20 20 21 21 require_once 'steps/mail/func.inc'; 22 23 $GLOBALS['EMAIL_ADDRESS_PATTERN'] = $EMAIL_ADDRESS_PATTERN; 22 24 } 23 25 … … 44 46 45 47 // render HTML in normal mode 46 $html = rcmail_ print_body($part, array('safe' => false));48 $html = rcmail_html4inline(rcmail_print_body($part, array('safe' => false)), 'foo'); 47 49 48 50 $this->assertPattern('/src="'.$part->replaces['ex1.jpg'].'"/', $html, "Replace reference to inline image"); … … 72 74 $part = $this->get_html_part('src/htmlxss.txt'); 73 75 $washed = rcmail_print_body($part, array('safe' => true)); 74 76 75 77 $this->assertNoPattern('/src="skins/', $washed, "Remove local references"); 76 $this->assertNoPattern('/\son[a-z]+/', $wahsed, "Remove on* attributes"); 77 $this->assertNoPattern('/alert/', $wahsed, "Remove alerts"); 78 $this->assertNoPattern('/\son[a-z]+/', $washed, "Remove on* attributes"); 79 80 $html = rcmail_html4inline($washed, 'foo'); 81 $this->assertNoPattern('/onclick="return rcmail.command(\'compose\',\'xss@somehost.net\',this)"/', $html, "Clean mailto links"); 82 $this->assertNoPattern('/alert/', $html, "Remove alerts"); 78 83 } 79 84 -
trunk/roundcubemail/tests/src/htmlxss.txt
r2323 r2324 4 4 <p><img onLoad.="alert(document.cookie)" src="skins/default/images/roundcube_logo.png" /></p> 5 5 6 <p><a href=" javascript:alert(document.cookie)">mail me!</a>6 <p><a href="mailto:xss@somehost.net') && alert(document.cookie) || ignore('">mail me!</a> 7 7 <a href="http://roundcube.net" target="_self">roundcube.net</a> 8 8 <a href="http://roundcube.net" \onmouseover="alert('XSS')">roundcube.net (2)</a>
Note: See TracChangeset
for help on using the changeset viewer.
