Changeset 5514 in subversion for branches/release-0.7/program/steps/mail/get.inc
- Timestamp:
- Nov 30, 2011 6:35:43 AM (19 months ago)
- File:
-
- 1 edited
-
branches/release-0.7/program/steps/mail/get.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-0.7/program/steps/mail/get.inc
r5481 r5514 135 135 header("Content-Disposition: $disposition; filename=\"$filename\""); 136 136 137 // turn off output buffering and print part content 138 if ($part->body) 139 echo $part->body; 140 else if ($part->size) 141 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 137 // do content filtering to avoid XSS through fake images 138 if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) { 139 if ($part->body) 140 echo preg_match('/<(script|iframe|object)/i', $part->body) ? '' : $part->body; 141 else if ($part->size) { 142 $stdout = fopen('php://output', 'w'); 143 stream_filter_register('rcube_content', 'rcube_content_filter') or die('Failed to register content filter'); 144 stream_filter_append($stdout, 'rcube_content'); 145 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $stdout); 146 } 147 } 148 else { 149 // turn off output buffering and print part content 150 if ($part->body) 151 echo $part->body; 152 else if ($part->size) 153 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 154 } 142 155 } 143 156 … … 167 180 168 181 182 183 /** 184 * PHP stream filter to detect html/javascript code in attachments 185 */ 186 class rcube_content_filter extends php_user_filter 187 { 188 private $buffer = ''; 189 private $cutoff = 2048; 190 191 function onCreate() 192 { 193 $this->cutoff = rand(2048, 3027); 194 return true; 195 } 196 197 function filter($in, $out, &$consumed, $closing) 198 { 199 while ($bucket = stream_bucket_make_writeable($in)) { 200 $this->buffer .= $bucket->data; 201 202 // check for evil content and abort 203 if (preg_match('/<(script|iframe|object)/i', $this->buffer)) 204 return PSFS_ERR_FATAL; 205 206 // keep buffer small enough 207 if (strlen($this->buffer) > 4096) 208 $this->buffer = substr($this->buffer, $this->cutoff); 209 210 $consumed += $bucket->datalen; 211 stream_bucket_append($out, $bucket); 212 } 213 214 return PSFS_PASS_ON; 215 } 216 } 217
Note: See TracChangeset
for help on using the changeset viewer.
