浏览代码

Fix Ipv4 mapped Ipv6 issue (#4606)

* Update index.php

* Update helpers.php

* Update index.php

* Run NPM format

---------

Co-authored-by: endrepavel <46920973+endrepavel@users.noreply.github.com>
Jaap Marcus 1 年之前
父节点
当前提交
ca6823bf2a
共有 2 个文件被更改,包括 11 次插入0 次删除
  1. 5 0
      web/inc/helpers.php
  2. 6 0
      web/login/index.php

+ 5 - 0
web/inc/helpers.php

@@ -113,6 +113,11 @@ function get_real_user_ip() {
 			$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
 		}
 	}
+
+	// Handling IPv4-mapped IPv6 address
+	if (strpos($ip, ":") === 0 && strpos($ip, ".") > 0) {
+		$ip = substr($ip, strrpos($ip, ":") + 1); // Strip IPv4 Compatibility notation
+	}
 	return $ip;
 }
 

+ 6 - 0
web/login/index.php

@@ -120,6 +120,12 @@ function authenticate_user($user, $password, $twofa = "") {
 				$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
 			}
 		}
+
+		// Handling IPv4-mapped IPv6 address
+		if (strpos($ip, ":") === 0 && strpos($ip, ".") > 0) {
+			$ip = substr($ip, strrpos($ip, ":") + 1); // Strip IPv4 Compatibility notation
+		}
+
 		$v_ip = quoteshellarg($ip);
 		$v_user_agent = quoteshellarg($user_agent);