[core] don't crash when REMOTE_ADDR is 'unix:', fixes #1076

This commit is contained in:
Shish 2024-02-22 23:14:04 +00:00 committed by Shish
parent c5fc001dbd
commit 4cc9b2f5d3

View file

@ -156,6 +156,9 @@ function is_trusted_proxy(): bool
}
// @phpstan-ignore-next-line - TRUSTED_PROXIES is defined in config
foreach(TRUSTED_PROXIES as $proxy) {
if($ra === $proxy) { // check for "unix:" before checking IPs
return true;
}
if(ip_in_range($ra, $proxy)) {
return true;
}
@ -170,6 +173,10 @@ function get_real_ip(): string
{
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == "unix:") {
$ip = "0.0.0.0";
}
if(is_trusted_proxy()) {
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
if(filter_var_ex($ip, FILTER_VALIDATE_IP)) {