Skip to content

Commit ca6823b

Browse files
Fix Ipv4 mapped Ipv6 issue (hestiacp#4606)
* Update index.php * Update helpers.php * Update index.php * Run NPM format --------- Co-authored-by: endrepavel <46920973+endrepavel@users.noreply.github.com>
1 parent 9b37fd2 commit ca6823b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

web/inc/helpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ function get_real_user_ip() {
113113
$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
114114
}
115115
}
116+
117+
// Handling IPv4-mapped IPv6 address
118+
if (strpos($ip, ":") === 0 && strpos($ip, ".") > 0) {
119+
$ip = substr($ip, strrpos($ip, ":") + 1); // Strip IPv4 Compatibility notation
120+
}
116121
return $ip;
117122
}
118123

web/login/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ function authenticate_user($user, $password, $twofa = "") {
120120
$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
121121
}
122122
}
123+
124+
// Handling IPv4-mapped IPv6 address
125+
if (strpos($ip, ":") === 0 && strpos($ip, ".") > 0) {
126+
$ip = substr($ip, strrpos($ip, ":") + 1); // Strip IPv4 Compatibility notation
127+
}
128+
123129
$v_ip = quoteshellarg($ip);
124130
$v_user_agent = quoteshellarg($user_agent);
125131

0 commit comments

Comments
 (0)