Changeset 2162 in subversion


Ignore:
Timestamp:
Dec 16, 2008 12:14:09 PM (4 years ago)
Author:
thomasb
Message:

Fix vulnerable bin scripts

Location:
branches/release-0.2-beta
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/release-0.2-beta/bin/html2text.php

    r1764 r2162  
    11<?php 
     2/* 
    23 
    3 define('INSTALL_PATH', realpath('./../') . '/'); 
     4 +-----------------------------------------------------------------------+ 
     5 | bin/html2text.php                                                     | 
     6 |                                                                       | 
     7 | This file is part of the RoundCube Webmail client                     | 
     8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 | 
     9 | Licensed under the GNU GPL                                            | 
     10 |                                                                       | 
     11 | PURPOSE:                                                              | 
     12 |   Convert HTML message to plain text                                  | 
     13 |                                                                       | 
     14 +-----------------------------------------------------------------------+ 
     15 | Author: Thomas Bruederli <roundcube@gmail.com>                        | 
     16 +-----------------------------------------------------------------------+ 
     17 
     18 $Id: html2text.php 2070 2008-11-20 10:29:34Z alec $ 
     19 
     20*/ 
     21 
     22define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/'); 
    423require INSTALL_PATH.'program/include/iniset.php'; 
    524 
    6 $converter = new html2text(html_entity_decode($HTTP_RAW_POST_DATA, ENT_COMPAT, 'UTF-8')); 
     25$converter = new html2text($HTTP_RAW_POST_DATA); 
    726 
    827header('Content-Type: text/plain; charset=UTF-8'); 
  • branches/release-0.2-beta/bin/quotaimg.php

    r1776 r2162  
    22/* 
    33 +-----------------------------------------------------------------------+ 
    4  | program/bin/quotaimg.php                                              | 
     4 | bin/quotaimg.php                                                      | 
    55 |                                                                       | 
    66 | This file is part of the RoundCube Webmail client                     | 
    7  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 | 
     7 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 | 
    88 | Licensed under the GNU GPL                                            | 
    99 |                                                                       | 
     
    1515 +-----------------------------------------------------------------------+ 
    1616 
    17  $Id: $ 
     17 $Id$ 
    1818 
    1919*/ 
    2020 
    21 $used   = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??'; 
    22 $quota  = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??'; 
    23 $width  = empty($_GET['w']) ? 100 : (int)$_GET['w']; 
    24 $height = empty($_GET['h']) ? 14 : (int)$_GET['h']; 
     21$used   = isset($_GET['u']) ? intval($_GET['u']) : '??'; 
     22$quota  = isset($_GET['q']) ? intval($_GET['q']) : '??'; 
     23$width  = empty($_GET['w']) ? 100 : min(300, intval($_GET['w'])); 
     24$height = empty($_GET['h']) ? 14  : min(50,  intval($_GET['h'])); 
    2525 
    2626/** 
     
    9797        if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) { 
    9898                return false;  
    99     } 
     99        } 
    100100 
    101         if (strpos($used, '?') !== false || strpos($total, '?') !== false 
    102         && $used != 0) { 
     101        if (strpos($used, '?') !== false || strpos($total, '?') !== false && $used != 0) { 
    103102                $unknown = true;  
    104     } 
     103        } 
    105104 
    106105        $im = imagecreate($width, $height); 
     
    154153                        $fill = imagecolorallocate($im, $r, $g, $b); 
    155154                } else { 
    156                     // if($quota >= $limit['low']) 
     155                        // if($quota >= $limit['low']) 
    157156                        list($r, $g, $b) = explode(',', $color['fill']['low']); 
    158157                        $fill = imagecolorallocate($im, $r, $g, $b); 
     
    164163                $string = $quota . '%'; 
    165164                $mid    = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; 
    166         // Print percent in black 
     165                // Print percent in black 
    167166                imagestring($im, $font, $mid, $padding, $string, $text);  
    168167        } 
    169168 
    170169        header('Content-Type: image/gif'); 
    171      
    172     // @todo is harcoding GMT necessary? 
    173         header('Expires: ' . gmdate('D, d M Y H:i:s', mktime()+86400) . ' GMT'); 
    174         header('Cache-Control: '); 
    175         header('Pragma: '); 
     170 
     171        // cache for 1 hour 
     172        $maxage = 3600; 
     173        header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$maxage). ' GMT'); 
     174        header('Cache-Control: max-age=' . $maxage); 
    176175         
    177176        imagegif($im); 
     
    179178} 
    180179 
    181 genQuota($used, $quota, $width, $height); 
     180if ($width > 1 && $height > 1) { 
     181        genQuota($used, $quota, $width, $height);   
     182} 
     183else { 
     184        header("HTTP/1.0 404 Not Found"); 
     185} 
     186 
    182187exit; 
    183188?> 
  • branches/release-0.2-beta/program/lib/html2text.php

    r1711 r2162  
    150150        '/<style[^>]*>.*?<\/style>/i',           // <style>s -- which strip_tags supposedly has problems with 
    151151        //'/<!-- .* -->/',                         // Comments -- which strip_tags might have problem a with 
    152         '/<h[123][^>]*>(.*?)<\/h[123]>/ie',      // H1 - H3 
    153         '/<h[456][^>]*>(.*?)<\/h[456]>/ie',      // H4 - H6 
    154152        '/<p[^>]*>/i',                           // <P> 
    155153        '/<br[^>]*>/i',                          // <br> 
    156         '/<b[^>]*>(.*?)<\/b>/ie',                // <b> 
    157         '/<strong[^>]*>(.*?)<\/strong>/ie',      // <strong> 
    158154        '/<i[^>]*>(.*?)<\/i>/i',                 // <i> 
    159155        '/<em[^>]*>(.*?)<\/em>/i',               // <em> 
     
    162158        '/<li[^>]*>(.*?)<\/li>/i',               // <li> and </li> 
    163159        '/<li[^>]*>/i',                          // <li> 
    164         '/<a [^>]*href=("|\')([^"\']+)\1[^>]*>(.*?)<\/a>/ie', 
    165                                                  // <a href=""> 
    166160        '/<hr[^>]*>/i',                          // <hr> 
    167161        '/(<table[^>]*>|<\/table>)/i',           // <table> and </table> 
    168162        '/(<tr[^>]*>|<\/tr>)/i',                 // <tr> and </tr> 
    169163        '/<td[^>]*>(.*?)<\/td>/i',               // <td> and </td> 
    170         '/<th[^>]*>(.*?)<\/th>/ie',              // <th> and </th> 
    171164        '/&(nbsp|#160);/i',                      // Non-breaking space 
    172165        '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i', 
     
    202195        '',                                     // <style>s -- which strip_tags supposedly has problems with 
    203196        //'',                                     // Comments -- which strip_tags might have problem a with 
    204         "strtoupper(\"\n\n\\1\n\n\")",          // H1 - H3 
    205         "ucwords(\"\n\n\\1\n\")",             // H4 - H6 
    206197        "\n\n",                               // <P> 
    207198        "\n",                                   // <br> 
    208         'strtoupper("\\1")',                    // <b> 
    209         'strtoupper("\\1")',                    // <strong> 
    210199        '_\\1_',                                // <i> 
    211200        '_\\1_',                                // <em> 
     
    214203        "\t* \\1\n",                            // <li> and </li> 
    215204        "\n\t* ",                               // <li> 
    216         '$this->_build_link_list("\\2", "\\3")', 
    217                                                 // <a href=""> 
    218205        "\n-------------------------\n",        // <hr> 
    219206        "\n\n",                                 // <table> and </table> 
    220207        "\n",                                   // <tr> and </tr> 
    221208        "\t\t\\1\n",                            // <td> and </td> 
    222         "strtoupper(\"\t\t\\1\n\")",            // <th> and </th> 
    223209        ' ',                                    // Non-breaking space 
    224210        '"',                                    // Double quotes 
     
    233219        '-', 
    234220        '*', 
    235         '£', 
     221        '£', 
    236222        'EUR',                                  // Euro sign. € ? 
    237223        '',                                     // Unknown/unhandled entities 
    238224        ' '                                     // Runs of spaces, post-handling 
     225    ); 
     226 
     227    /** 
     228     *  List of preg* regular expression patterns to search for 
     229     *  and replace using callback function. 
     230     * 
     231     *  @var array $callback_search 
     232     *  @access public 
     233     */ 
     234    var $callback_search = array( 
     235        '/<(h)[123456][^>]*>(.*?)<\/h[123456]>/i', // H1 - H3 
     236        '/<(b)[^>]*>(.*?)<\/b>/i',                 // <b> 
     237        '/<(strong)[^>]*>(.*?)<\/strong>/i',       // <strong> 
     238        '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', 
     239                                                   // <a href=""> 
     240        '/<(th)[^>]*>(.*?)<\/th>/i',               // <th> and </th> 
    239241    ); 
    240242 
     
    466468        // Convert <PRE> 
    467469        $this->_convert_pre($text); 
    468          
     470 
     471        // Replace known html entities 
     472        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); 
     473 
    469474        // Run our defined search-and-replace 
    470475        $text = preg_replace($this->search, $this->replace, $text); 
     476        $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text); 
    471477 
    472478        // Strip any other HTML tags 
     
    544550        { 
    545551            $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]); 
    546             $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text); 
     552            $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1); 
    547553        } 
    548554    } 
     555 
     556    /** 
     557     *  Callback function for preg_replace_callback use. 
     558     * 
     559     *  @param  array PREG matches 
     560     *  @return string 
     561     *  @access private 
     562     */ 
     563    function _preg_callback($matches) 
     564    { 
     565        switch($matches[1]) 
     566        { 
     567            case 'b': 
     568            case 'strong': 
     569                return $this->_strtoupper($matches[2]); 
     570            case 'hr': 
     571                return $this->_strtoupper("\t\t". $matches[2] ."\n"); 
     572            case 'h': 
     573                return $this->_strtoupper("\n\n". $matches[2] ."\n\n"); 
     574            case 'a': 
     575                return $this->_build_link_list($matches[3], $matches[4]); 
     576        } 
     577    } 
     578     
     579    /** 
     580     *  Strtoupper multibyte wrapper function 
     581     * 
     582     *  @param  string 
     583     *  @return string 
     584     *  @access private 
     585     */ 
     586    function _strtoupper($str) 
     587    { 
     588        if (function_exists('mb_strtoupper')) 
     589            return mb_strtoupper($str); 
     590        else 
     591            return strtoupper($str); 
     592    } 
    549593} 
    550594 
Note: See TracChangeset for help on using the changeset viewer.