IPBlocking to route groups (e.g., web, api), which may conflict with existing middleware (e.g., auth, throttle).IPBlocking in the stack (e.g., after auth) could bypass intended restrictions.$request->ip() vs. $request->server('REMOTE_ADDR')).auth, rate limiting)?trustedproxies + middleware achieve this with less overhead?HandleIncomingRequest).composer require webtoppings/ipwhitelisting
php artisan vendor:publish --provider="WebToppings\IPWhitelisting\IPWhitelistingServiceProvider"
php artisan migrate
app/Http/Kernel.php:
'web' => [
\WebToppings\IPWhitelisting\Middlewares\IPBlocking::class,
// ... other middleware
],
Route::middleware(['IPBlocking'])->group(function () {
// Protected routes
});
routes/web.php:
Route::resource('/admin/ip-whitelist', '\WebToppings\IPWhitelisting\IPWhitelistingController');
curl or Postman using a non-whitelisted IP (should return 403).trustedproxies in AppServiceProvider:
$this->middleware(function ($request, $next) {
if ($request->ip() === '127.0.0.1') { // Fallback for local testing
return $next($request);
}
return $next($request);
});
IPBlocking is added to the api middleware group in Kernel.php.artisan command).composer.json until stability is confirmed.REMOTE_ADDR/CF-Connecting-IP (Cloudflare) is correctly configured.IPBlocking must run before route resolution.public function handle($request, Closure $next) {
\Log::info('IP Check:', ['ip' => $request->ip()]);
// ...
}
redis:whitelist) and invalidate on changes.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database downtime | All requests blocked (403) | Use a fallback (e.g., allowlist a backup IP). |
| Middleware misconfiguration | Unintended access or blocks | Test in staging; use feature flags. |
| Large whitelist | Slow response times | Cache whitelist; optimize database queries. |
| Proxy misconfiguration | Incorrect IP detection | Test with curl -H "CF-Connecting-IP: ...". |
| No whitelisted IPs configured | All users blocked | Seed initial IPs via migration/seeder. |
IPBlocking middleware from Kernel.php.How can I help you explore Laravel packages today?