From 96c946ee6ced0a9a68ef251528a3f900d5a01396 Mon Sep 17 00:00:00 2001 From: alecpl Date: Wed, 21 Dec 2011 10:07:42 +0000 Subject: - Applied fixes from trunk up to r5633 --- program/include/rcube_content_filter.php | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 program/include/rcube_content_filter.php (limited to 'program/include') diff --git a/program/include/rcube_content_filter.php b/program/include/rcube_content_filter.php new file mode 100644 index 000000000..430defec6 --- /dev/null +++ b/program/include/rcube_content_filter.php @@ -0,0 +1,55 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ +*/ + +/** + * PHP stream filter to detect html/javascript code in attachments + */ +class rcube_content_filter extends php_user_filter +{ + private $buffer = ''; + private $cutoff = 2048; + + function onCreate() + { + $this->cutoff = rand(2048, 3027); + return true; + } + + function filter($in, $out, &$consumed, $closing) + { + while ($bucket = stream_bucket_make_writeable($in)) { + $this->buffer .= $bucket->data; + + // check for evil content and abort + if (preg_match('/<(script|iframe|object)/i', $this->buffer)) + return PSFS_ERR_FATAL; + + // keep buffer small enough + if (strlen($this->buffer) > 4096) + $this->buffer = substr($this->buffer, $this->cutoff); + + $consumed += $bucket->datalen; + stream_bucket_append($out, $bucket); + } + + return PSFS_PASS_ON; + } +} + -- cgit v1.2.3