Skip to content

Commit

Permalink
Simplify IP address validation
Browse files Browse the repository at this point in the history
- check IPv4 and IPv6 in one call
- type strict checking of return value

See issue #12389

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jul 29, 2016
1 parent 25b4d84 commit 314ec0a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions libraries/ip_allow_deny.lib.php
Expand Up @@ -33,11 +33,10 @@ function PMA_getIp()
$trusted_header_value
= PMA_getenv($GLOBALS['cfg']['TrustedProxies'][$direct_ip]);
$matches = array();
// the $ checks that the header contains only one IP address,
// ?: makes sure the () don't capture
$is_ip = (filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
// checks that the header contains only one IP address,
$is_ip = filter_var($trusted_header_value, FILTER_VALIDATE_IP);

if ($is_ip) {
if ($is_ip !== false) {
// True IP behind a proxy
return $trusted_header_value;
}
Expand Down

0 comments on commit 314ec0a

Please sign in to comment.