🆙 More fixes 🆙

This commit is contained in:
Remco
2026-01-19 22:19:41 +01:00
parent e561acb897
commit 8f2a2fdc37
3 changed files with 27 additions and 13 deletions
@@ -15,7 +15,7 @@ class LogViewerMiddleware
return to_route('login'); return to_route('login');
} }
if (hasPermission('view_server_logs') === '' || hasPermission('view_server_logs') === '0') { if (! hasPermission('view_server_logs')) {
abort(403); abort(403);
} }
@@ -18,22 +18,22 @@ class RealClientIpMiddleware
]; ];
foreach ($proxyHeaders as $header) { foreach ($proxyHeaders as $header) {
if (! empty(\Illuminate\Support\Facades\Request::server($header))) { $value = $request->server->get($header);
$ip = \Illuminate\Support\Facades\Request::server($header); if (is_string($value) && $value !== '') {
if (str_contains((string) $ip, ',')) { $candidate = $value;
[$ip] = explode(',', (string) $ip); if (str_contains($candidate, ',')) {
[$candidate] = explode(',', $candidate);
} }
$ip = trim((string) $ip); $candidate = trim($candidate);
if (filter_var($ip, FILTER_VALIDATE_IP)) { if (filter_var($candidate, FILTER_VALIDATE_IP)) {
// Set the real IP as REMOTE_ADDR $request->server->set('REMOTE_ADDR', $candidate);
$request->server->set('REMOTE_ADDR', $ip);
break; break;
} }
} }
} }
// Special handling for REMOTE_ADDR with multiple IPs // Special handling for REMOTE_ADDR with multiple IPs
$remoteAddr = \Illuminate\Support\Facades\Request::server('REMOTE_ADDR'); $remoteAddr = $request->server->get('REMOTE_ADDR');
if (is_string($remoteAddr) && str_contains($remoteAddr, ',')) { if (is_string($remoteAddr) && str_contains($remoteAddr, ',')) {
[$ip] = explode(',', $remoteAddr); [$ip] = explode(',', $remoteAddr);
$ip = trim($ip); $ip = trim($ip);
@@ -40,7 +40,18 @@ class VPNCheckerMiddleware
$userIp = $request->ip(); $userIp = $request->ip();
$apiResponse = $ipService->ipLookup($userIp); $apiResponse = $ipService->ipLookup($userIp);
$asn = $apiResponse['asn']['asn'] ?? ''; $asn = '';
if (is_array($apiResponse)) {
$asnSection = $apiResponse['asn'] ?? null;
if (is_array($asnSection)) {
$asnValue = $asnSection['asn'] ?? null;
if (is_string($asnValue)) {
$asn = $asnValue;
} elseif (is_int($asnValue)) {
$asn = (string) $asnValue;
}
}
}
$asnWhitelisted = WebsiteIpWhitelist::where('asn', $asn) $asnWhitelisted = WebsiteIpWhitelist::where('asn', $asn)
->where('whitelist_asn', '=', '1') ->where('whitelist_asn', '=', '1')
->exists(); ->exists();
@@ -61,8 +72,11 @@ class VPNCheckerMiddleware
]); ]);
} }
if (isset($apiResponse['threat']) && is_array($apiResponse['threat'])) { if (is_array($apiResponse) && isset($apiResponse['threat']) && is_array($apiResponse['threat'])) {
$filteredThreats = array_diff_key($apiResponse['threat'], array_flip(['blocklists', 'is_icloud_relay', 'is_datacenter', 'is_tor', 'is_proxy'])); $filteredThreats = array_diff_key(
$apiResponse['threat'],
array_flip(['blocklists', 'is_icloud_relay', 'is_datacenter', 'is_tor', 'is_proxy'])
);
if (in_array(true, $filteredThreats, true)) { if (in_array(true, $filteredThreats, true)) {
WebsiteIpBlacklist::create([ WebsiteIpBlacklist::create([