From ba6f21caeb405c7e8512a09941fefbc97286e45f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 21 Nov 2012 19:52:03 +0100 Subject: Framework files moved to lib/Roundcube --- program/lib/Roundcube/rcube_content_filter.php | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 program/lib/Roundcube/rcube_content_filter.php (limited to 'program/lib/Roundcube/rcube_content_filter.php') diff --git a/program/lib/Roundcube/rcube_content_filter.php b/program/lib/Roundcube/rcube_content_filter.php new file mode 100644 index 000000000..99916a300 --- /dev/null +++ b/program/lib/Roundcube/rcube_content_filter.php @@ -0,0 +1,60 @@ + | + +-----------------------------------------------------------------------+ +*/ + +/** + * PHP stream filter to detect html/javascript code in attachments + * + * @package Framework + * @subpackage Core + */ +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