Changeset 598 for trunk/lib


Ignore:
Timestamp:
Apr 27, 2017 2:56:05 PM (7 years ago)
Author:
anonymous
Message:

Strip non-IP address data from proxy-server-provided IP addresses (e.g., 'for=189.211.197.173'). Fix bug with mispelt referer variable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r591 r598  
    12611261            if (array_key_exists($key, $_SERVER)) {
    12621262                foreach (explode(',', $_SERVER[$key]) as $addr) {
     1263                    // Strip non-address data to avoid "PHP Warning:  inet_pton(): Unrecognized address for=189.211.197.173 in ./Utilities.inc.php on line 1293"
     1264                    $addr = preg_replace('/[^=]=/', '', $addr);
    12631265                    $addr = canonicalIPAddr(trim($addr));
    12641266                    if (false !== filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
     
    13941396{
    13951397    $current_url = absoluteMe();
    1396     $referer_url = getenv('HTTP_REFERER');
     1398    $referrer_url = getenv('HTTP_REFERER');
    13971399
    13981400    // If one of the hostnames is an IP address, compare only the path of both.
    13991401    if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($current_url, PHP_URL_HOST)) || preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($referrer_url, PHP_URL_HOST))) {
    14001402        $current_url = preg_replace('@^https?://[^/]+@', '', $current_url);
    1401         $referer_url = preg_replace('@^https?://[^/]+@', '', $referer_url);
     1403        $referrer_url = preg_replace('@^https?://[^/]+@', '', $referrer_url);
    14021404    }
    14031405
    14041406    if ($exclude_query) {
    1405         return (stripQuery($current_url) == stripQuery($referer_url));
     1407        return (stripQuery($current_url) == stripQuery($referrer_url));
    14061408    } else {
    14071409        $app =& App::getInstance();
    1408         $app->logMsg(sprintf('refererIsMe comparison: %s == %s', $current_url, $referer_url), LOG_DEBUG, __FILE__, __LINE__);
    1409         return ($current_url == $referer_url);
     1410        $app->logMsg(sprintf('refererIsMe comparison: %s == %s', $current_url, $referrer_url), LOG_DEBUG, __FILE__, __LINE__);
     1411        return ($current_url == $referrer_url);
    14101412    }
    14111413}
Note: See TracChangeset for help on using the changeset viewer.