pratik-dabhi/laravel-firewall
Laravel firewall middleware for blocking abusive traffic by IP rules such as allow/deny lists and access restrictions. Helps protect routes and applications from unwanted requests with simple configuration and integration into a Laravel app.
| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Performance Overhead | GeoIP lookups and rate limiting checks add latency (~1–5ms per request). High-traffic apps may need caching (e.g., Redis for GeoIP data). | Benchmark under load; use Redis for GeoIP caching and rate-limiting storage. |
| False Positives/Negatives | GeoIP blocking may incorrectly block legitimate users (e.g., VPNs, corporate networks). IP rules require manual maintenance. | Start with whitelisting critical IPs; use IP reputation services (e.g., AbuseIPDB) for dynamic blocking. |
| Dependency Bloat | Adds new dependencies (geoip2/geoip2, spatie/laravel-rate-limiting). May conflict with existing security packages (e.g., spatie/laravel-honeypot). |
Audit dependencies for version conflicts; test in staging before production. |
| Logging Overhead | Attack logging may bloat storage if not filtered. | Configure log rotation and retention policies; exclude non-critical endpoints. |
| Maintenance Burden | Rules (IPs, GeoIP countries) require ongoing updates. | Automate rule updates via webhooks (e.g., from threat intelligence feeds) or cron jobs. |
| Laravel Component | Package Integration Point | Compatibility Notes |
|---|---|---|
| Middleware Pipeline | Registers FirewallMiddleware in app/Http/Kernel.php (runs before auth, throttle). |
Works with Laravel 10+; no breaking changes expected. |
| Service Container | Binds FirewallService for rule resolution (IP, GeoIP, rate limiting). |
Uses Laravel’s container for dependency injection; no custom DI needed. |
| Config System | Rules defined in config/firewall.php (supports database-backed rules). |
Overrides via environment variables or database migrations supported. |
| Rate Limiting | Extends Laravel’s throttle middleware with custom rules. |
Conflicts possible if using spatie/laravel-rate-limiting; prioritize one solution. |
| Logging | Logs to Laravel’s Monolog channel (can be extended to Syslog, ELK, etc.). |
Ensure log drivers (e.g., single, stack) are configured for external forwarding. |
| GeoIP Data | Uses geoip2/geoip2 library (requires MaxMind GeoLite2 database). |
Database must be updated regularly (MaxMind provides free/paid updates). |
throttle, custom IP checks).spatie/laravel-honeypot).composer require pratik-dabhi/laravel-firewall.match expression usage).throttle; disable existing rate-limiting middleware to avoid conflicts.geoipupdate or manual download).php artisan vendor:publish --provider="PratikDabhi\Firewall\FirewallServiceProvider".Kernel.php:
protected $middleware = [
\PratikDabhi\Firewall\Middleware\FirewallMiddleware::class,
];
config/firewall.php or database.['RU', 'CN']).config/firewall.php:
'rate_limiting' => [
'enabled' => true,
'max_attempts' => 100,
'decay_minutes' => 1,
],
FirewallService to custom log handlers (e.g., SIEM).| Task | Frequency | Owner | Effort | Tools/Notes
How can I help you explore Laravel packages today?