Ignore:
Timestamp:
05/15/08 22:25:54 (4 years ago)
Author:
hverton
Message:

Merged trunk revisions 1342:1407 into the PLi-Fusion branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PLi-Fusion/includes/core_functions.php

    r1335 r1408  
    4949// prevent any possible XSS attacks via $_GET. 
    5050foreach ($_GET as $check_url) { 
    51     if ((eregi("<[^>]*script*\"?[^>]*>", $check_url)) || (eregi("<[^>]*object*\"?[^>]*>", $check_url)) || 
    52         (eregi("<[^>]*iframe*\"?[^>]*>", $check_url)) || (eregi("<[^>]*applet*\"?[^>]*>", $check_url)) || 
    53         (eregi("<[^>]*meta*\"?[^>]*>", $check_url)) || (eregi("<[^>]*style*\"?[^>]*>", $check_url)) || 
    54         (eregi("<[^>]*form*\"?[^>]*>", $check_url)) || (eregi("\([^>]*\"?[^)]*\)", $check_url))) { 
    55     die (); 
     51    // deal with array's in GET parameters 
     52    if (is_array($check_url)) { 
     53        foreach ($check_url as $url_parts) { 
     54            if ((eregi("<[^>]*script*\"?[^>]*>", $url_parts)) || (eregi("<[^>]*object*\"?[^>]*>", $url_parts)) || 
     55                    (eregi("<[^>]*iframe*\"?[^>]*>", $url_parts)) || (eregi("<[^>]*applet*\"?[^>]*>", $url_parts)) || 
     56                    (eregi("<[^>]*meta*\"?[^>]*>", $url_parts)) || (eregi("<[^>]*style*\"?[^>]*>", $url_parts)) || 
     57                    (eregi("<[^>]*form*\"?[^>]*>", $url_parts)) || (eregi("\([^>]*\"?[^)]*\)", $url_parts))) { 
     58                die (); 
     59            } 
     60        } 
     61    } else { 
     62        if ((eregi("<[^>]*script*\"?[^>]*>", $check_url)) || (eregi("<[^>]*object*\"?[^>]*>", $check_url)) || 
     63                (eregi("<[^>]*iframe*\"?[^>]*>", $check_url)) || (eregi("<[^>]*applet*\"?[^>]*>", $check_url)) || 
     64                (eregi("<[^>]*meta*\"?[^>]*>", $check_url)) || (eregi("<[^>]*style*\"?[^>]*>", $check_url)) || 
     65                (eregi("<[^>]*form*\"?[^>]*>", $check_url)) || (eregi("\([^>]*\"?[^)]*\)", $check_url))) { 
     66            die (); 
     67        } 
    5668    } 
    5769} 
     
    524536} 
    525537 
     538// internal function: preg_replace_callback for parseubb, to validate the URL found in [url] 
     539function _parseubb_checkurl($matches) { 
     540 
     541    // if it's a old-style bbcode (not [url=][/url] but [url][/url]), convert it before checking 
     542    if (empty($matches[2])) { 
     543        $matches[2] = $matches[3]; 
     544    } 
     545 
     546    // Build the regex to check the URL 
     547    $scheme = "(https?|s?ftp|mailto|svn|cvs|callto|mms|skype)\:\/\/";           // SCHEMES supported 
     548    $urlregex = "^(".$scheme.")?";                                              // make the scheme optional 
     549    $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";   // USERID + PASSWORD (optional) 
     550    $urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*";                           // HOSTNAME or IP 
     551    $urlregex .= "(\:[0-9]{2,5})?";                                             // PORT (optional) 
     552    $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?";                                 // PATH (optional) 
     553    $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";                     // GET querystring (optional) 
     554    $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";                               // ANCHOR (optional) 
     555 
     556    // validate the URL (in $matches[1]) 
     557    if (eregi($urlregex, $matches[2])) { 
     558        // check if the URL is prefixed. If not, assume http:// 
     559        if (!eregi("^(".$scheme."){1}", $matches[2])) { 
     560            $matches[2] = "http://".$matches[2]; 
     561        } 
     562        // return the html for the URL bbcode 
     563        return "<a href='".$matches[2]."' alt='' target='_blank'>".$matches[3]."</a>"; 
     564    } else { 
     565        // make the bbcode passed harmless 
     566        return stripinput($matches[0]); 
     567    } 
     568} 
     569 
    526570// Parse bbcode into HTML code 
    527571function parseubb($text) { 
     
    550594    // correct illegal [url=] BBcode 
    551595    $text = str_replace("[url=]", "[url]", $text); 
    552          
    553     $text = preg_replace('#\[url\]([\r\n]*)(http://|ftp://|https://|ftps://)([^\s\'\";\+]*?)([\r\n]*)\[/url\]#si', '<a href=\'\2\3\' target=\'_blank\'>\2\3</a>', $text); 
    554     $text = preg_replace('#\[url\]([\r\n]*)([^\s\'\";\+]*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\'>\2</a>', $text); 
    555     $text = preg_replace('#\[url=([\r\n]*)(http://|ftp://|https://|ftps://)([^\'\";]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'\2\3\' target=\'_blank\'>\4</a>', $text); 
    556     $text = preg_replace('#\[url=([\r\n]*)([^\s\'\";\+]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\'>\3</a>', $text); 
    557  
     596 
     597    // convert URL bbcode, strip non-valid URL's 
     598    $text = preg_replace_callback('#\[url(=)?(.*?)\](.*?)([\r\n]*)\[/url\]#si', '_parseubb_checkurl', $text); 
     599 
     600    // convert mail bbcode 
    558601    $text = preg_replace('#\[mail\]([\r\n]*)([^\s\'\";:\+]*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\2</a>', $text); 
    559602    $text = preg_replace('#\[mail=([\r\n]*)([^\s\'\";:\+]*?)\](.*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\3</a>', $text); 
    560603     
    561604    $text = preg_replace('#\[small\](.*?)\[/small\]#si', '<span class=\'small\'>\1</span>', $text); 
    562     $text = preg_replace('#\[color=(\#[0-9a-fA-F]{6}|black|blue|brown|cyan|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|violet|white|yellow)\](.*?)\[/color\]#si', '<span style=\'color:\1\'>\2</span>', $text); 
     605    $text = preg_replace('#\[color=(\#[0-9a-fA-F]{6}|black|blue|brown|cyan|grey|green|lime|maroon|navy|olive|orange|purple|red|silver|violet|white|yellow)\](.*?)\[/color\]#si', '<span style=\'color:\1\'>\2</span>', $text); 
    563606     
    564607    $text = preg_replace('#\[flash width=([0-9]*?) height=([0-9]*?)\]([^\s\'\";:\+]*?)(\.swf)\[/flash\]#si', '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://active.macromedia.com/flash6/cabs/swflash.cab#version=6,0,0,0\' id=\'\3\4\' width=\'\1\' height=\'\2\'><param name=movie value=\'\3\4\'><param name=\'quality\' value=\'high\'><param name=\'bgcolor\' value=\'#ffffff\'><embed src=\'\3\4\' quality=\'high\' bgcolor=\'#ffffff\' width=\'\1\' height=\'\2\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'></embed></object>', $text); 
Note: See TracChangeset for help on using the changeset viewer.