🆙 More fixes 🆙

This commit is contained in:
Remco
2026-01-19 22:21:47 +01:00
parent bd2ae118bd
commit d5ecb09137
2 changed files with 31 additions and 16 deletions
@@ -42,6 +42,8 @@ class RealClientIpMiddleware
} }
} }
return $next($request); $response = $next($request);
assert($response instanceof \Symfony\Component\HttpFoundation\Response);
return $response;
} }
} }
@@ -15,17 +15,23 @@ class VPNCheckerMiddleware
{ {
// Skip check if vpn checker is disabled // Skip check if vpn checker is disabled
if (setting('vpn_block_enabled') === '0' || setting('ipdata_api_key') === 'ADD-API-KEY-HERE') { if (setting('vpn_block_enabled') === '0' || setting('ipdata_api_key') === 'ADD-API-KEY-HERE') {
return $next($request); $response = $next($request);
assert($response instanceof Response);
return $response;
} }
// Skip check if the rank is allowed to bypass the checker // Skip check if the rank is allowed to bypass the checker
if (hasPermission('bypass_vpn')) { if (hasPermission('bypass_vpn')) {
return $next($request); $response = $next($request);
assert($response instanceof Response);
return $response;
} }
// Skip check if the IP is in the whitelist table // Skip check if the IP is in the whitelist table
if (WebsiteIpWhitelist::where('ip_address', $request->ip())->exists()) { if (WebsiteIpWhitelist::where('ip_address', $request->ip())->exists()) {
return $next($request); $response = $next($request);
assert($response instanceof Response);
return $response;
} }
// Restrict user if IP is blacklisted // Restrict user if IP is blacklisted
@@ -38,18 +44,21 @@ class VPNCheckerMiddleware
// Instantiate the necessary things to look up the visitor IP // Instantiate the necessary things to look up the visitor IP
$ipService = new IpLookupService(setting('ipdata_api_key')); $ipService = new IpLookupService(setting('ipdata_api_key'));
$userIp = $request->ip(); $userIp = $request->ip();
if (! is_string($userIp) || $userIp === '') {
$response = $next($request);
assert($response instanceof Response);
return $response;
}
$apiResponse = $ipService->ipLookup($userIp); $apiResponse = $ipService->ipLookup($userIp);
$asn = ''; $asn = '';
if (is_array($apiResponse)) { $asnSection = $apiResponse['asn'] ?? null;
$asnSection = $apiResponse['asn'] ?? null; if (is_array($asnSection)) {
if (is_array($asnSection)) { $asnValue = $asnSection['asn'] ?? null;
$asnValue = $asnSection['asn'] ?? null; if (is_string($asnValue)) {
if (is_string($asnValue)) { $asn = $asnValue;
$asn = $asnValue; } elseif (is_int($asnValue)) {
} elseif (is_int($asnValue)) { $asn = (string) $asnValue;
$asn = (string) $asnValue;
}
} }
} }
$asnWhitelisted = WebsiteIpWhitelist::where('asn', $asn) $asnWhitelisted = WebsiteIpWhitelist::where('asn', $asn)
@@ -57,7 +66,9 @@ class VPNCheckerMiddleware
->exists(); ->exists();
if ($asnWhitelisted) { if ($asnWhitelisted) {
return $next($request); $response = $next($request);
assert($response instanceof Response);
return $response;
} }
// Fetch all blacklisted ASNs // Fetch all blacklisted ASNs
@@ -72,7 +83,7 @@ class VPNCheckerMiddleware
]); ]);
} }
if (is_array($apiResponse) && isset($apiResponse['threat']) && is_array($apiResponse['threat'])) { if (isset($apiResponse['threat']) && is_array($apiResponse['threat'])) {
$filteredThreats = array_diff_key( $filteredThreats = array_diff_key(
$apiResponse['threat'], $apiResponse['threat'],
array_flip(['blocklists', 'is_icloud_relay', 'is_datacenter', 'is_tor', 'is_proxy']) array_flip(['blocklists', 'is_icloud_relay', 'is_datacenter', 'is_tor', 'is_proxy'])
@@ -90,6 +101,8 @@ class VPNCheckerMiddleware
} }
} }
return $next($request); $response = $next($request);
assert($response instanceof Response);
return $response;
} }
} }