Menu

#127 Security vulnerability, not documented

open
nobody
None
5
2012-06-08
2012-06-08
Anonymous
No

\"Get real client ip address\" should be renamed to \"Get spoofed client ip address\". The function name should be renamed to \"phpwhois_getclientip_unsafe\" with a documented explanation of the security vulnerability.

HTTP_X_FORWARDED and such are read from HTTP headers such as X-Forwarded-For which are trivial to add to a request.

//-----------------------------------------------------------------
// Get real client ip address

function phpwhois_getclientip()
{
if (!empty($_SERVER[\'HTTP_CLIENT_IP\']) && phpwhois_validip($_SERVER[\'HTTP_CLIENT_IP\']))
return $_SERVER[\'HTTP_CLIENT_IP\'];

if (!empty($_SERVER[\'HTTP_X_FORWARDED_FOR\']))
foreach (explode(\',\',$_SERVER[\'HTTP_X_FORWARDED_FOR\']) as $ip)
if (phpwhois_validip(trim($ip)))
return $ip;

if (!empty($_SERVER[\'HTTP_X_FORWARDED\']) && phpwhois_validip($_SERVER[\'HTTP_X_FORWARDED\']))
return $_SERVER[\'HTTP_X_FORWARDED\'];

if (!empty($_SERVER[\'HTTP_FORWARDED_FOR\']) && phpwhois_validip($_SERVER[\'HTTP_FORWARDED_FOR\']))
return $_SERVER[\'HTTP_FORWARDED_FOR\'];

if (!empty($_SERVER[\'HTTP_FORWARDED\']) && phpwhois_validip($_SERVER[\'HTTP_FORWARDED\']))
return $_SERVER[\'HTTP_FORWARDED\'];

if (!empty($_SERVER[\'HTTP_X_FORWARDED\']) && phpwhois_validip($_SERVER[\'HTTP_X_FORWARDED\']))
return $_SERVER[\'HTTP_X_FORWARDED\'];

return $_SERVER[\'REMOTE_ADDR\'];
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.