kanopi / firewall
Evaluate the requests for malicious items.
Requires
- php: >=8.1
- amphp/dns: ^2.4
- doctrine/dbal: ^4.2
- geoip2/geoip2: ~2 || ^3
- guzzlehttp/guzzle: ^7.9
- jaybizzle/crawler-detect: ^1.4
- kanopi/crs-engine: ^1.0
- matomo/device-detector: ^6.4
- monolog/monolog: ^3.9
- symfony/cache: ~6.4 || ~7.3
- symfony/http-foundation: ~6.4 || ~7.3
- symfony/property-access: ~6.4 || ~7.3
- symfony/uid: ~6.4 || ~7.3
- symfony/yaml: ~6.4 || ~7.3
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- dg/bypass-finals: ^1.9
- phpcompatibility/php-compatibility: ^9.3
- phpstan/phpstan: ^2.1 <2.2.6
- phpunit/phpunit: ^10.5 || ^11.5
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^3.13
- symfony/dotenv: ~6.4 || ~7.3
- symfony/var-dumper: ~6.4 || ~7.3
Suggests
- ext-redis: Required only by Kanopi\Firewall\RateLimitStorage\RedisRateLimitStorage, for distributed rate limiting. Every other rate-limit backend (memory, file, database, PSR-6 cache) works without it.
This package is auto-updated.
Last update: 2026-07-31 16:11:24 UTC
README
Lite Firewall is a powerful, extensible request-evaluation library for PHP-based systems. It analyzes HTTP requests and applies configurable rules to allow, challenge, or block access based on IP addresses, geolocation, user agents, URLs, ASN (Autonomous System Numbers), rate limits, vulnerability scoring, and the OWASP Core Rule Set.
It is framework agnostic — it works with Drupal, WordPress, Symfony, Laravel, or any standalone PHP application.
📖 Documentation
Start at the documentation index.
This README is a short introduction. Everything else — the complete configuration
reference, every plugin, the shipped presets, platform integration, and the
contribution guide — is in docs/, and published at
kanopi.github.io/firewall.
| Getting Started | Install, configure, and block your first request |
| Configuration | Every YAML key, with defaults |
| Plugins | The ten built-in request evaluators |
| Presets | Ready-made rule sets you can include in one line |
| Guides | Error handling, custom plugins, custom storage, GeoIP setup |
| Reference | Rate-limit rules and the legacy config format |
| Contributing | Development setup, tests, and the PR checklist |
The docs source is the docs/ directory in this repository. See
Writing Documentation
to contribute a change.
Features
- Flexible Plugin System: Modular architecture allows for easy extension and customization
- Multiple Storage Backends: In-memory, file-based, and database storage for blocked clients, plus in-memory, file, database, PSR-6 cache, and Redis backends for rate-limit counters — or bring your own
- Comprehensive Request Analysis: Evaluate requests based on IP, location, ASN, user agent, URL patterns, and more
- OWASP Core Rule Set: Real CRS rules (SQLi, XSS, LFI/RFI, RCE, scanners) with tunable paranoia levels
- IP Reputation: Turn away addresses reported to AbuseIPDB, cached to stay inside the free tier and failing open when the service is unreachable
- Vulnerability Scoring: Advanced risk assessment based on multiple factors with configurable thresholds
- Rate Limiting: Built-in rate limiting with configurable storage backends
- Challenge Responses: Serve a proof-of-effort interstitial instead of a hard block, with HMAC-signed, IP-bound pass tokens
- GeoIP Integration: Full support for MaxMind GeoIP2 databases (both local and web service)
- Advanced Conditional Logic: Support for simple, complex, and grouped conditional rules
- Escalating Bans: Repeat offenders can be banned for progressively longer, up to permanently
- Remote Configuration Support: Load configuration files from remote URLs with local caching
- PSR-3 Compatible Logging: Integration with Monolog for flexible logging, with sensitive headers redacted by default
- Framework Agnostic: Works with any PHP application or framework — block, log-only, or throw exceptions for your framework to handle
Requirements
- PHP 8.1 or higher
- Composer
- Optional: MaxMind GeoIP2 databases for geolocation features
- Optional: Redis for distributed rate limiting
Installation
composer require kanopi/firewall
Quick Start
Place the following in your application's entry point (index.php, wp-config.php, or Drupal's settings.php):
<?php require_once __DIR__ . '/vendor/autoload.php'; if (class_exists('\Kanopi\Firewall\Firewall')) { \Kanopi\Firewall\Firewall::create([__DIR__ . '/config/firewall.yml'])->evaluate(); }
⚠️ Configure trusted proxies before calling
Firewall::create()Every plugin evaluates
$request->getClientIp(). Symfony only honorsX-Forwarded-For/Forwarded/X-Real-IPwhen you have calledRequest::setTrustedProxies(...). If your application sits behind a load balancer, CDN, or reverse proxy and you skip this, attackers can spoof their source IP and bypass IP allow-lists, block-lists, and per-IP rate limits.use Symfony\Component\HttpFoundation\Request; Request::setTrustedProxies( ['10.0.0.0/8', '192.168.0.0/16'], // YOUR proxy CIDRs Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PROTO );See Trusted Proxies.
Create a config/firewall.yml:
# Where blocked clients are stored storage: type: "Kanopi\\Firewall\\Storage\\FileStorage" config: storage_file: /var/log/firewall/blocked.data # Plugins evaluated for every request plugins: - plugin: "Kanopi\\Firewall\\Plugins\\IpAddress" response: block enable: true config: - 192.168.1.100 - 10.0.0.0/24 # Optional: log firewall events logger: - class: Monolog\Handler\StreamHandler args: - logs/firewall.log # relative to this YAML's directory - Monolog\Level::Info
Want a preset instead of writing rules by hand?
configs: - "{presets_dir}/malicious-requests.yml"
Continue with the Quick Start or the five-minute Test Drive.
Local Development
composer install # Install dependencies composer test # Run the test suite composer cs # Check code style composer stan # Run static analysis composer demo # Run the demo app at http://localhost:8000
To preview the documentation site locally:
python3 -m venv .venv-docs source .venv-docs/bin/activate pip install -r docs/requirements.txt mkdocs serve # http://127.0.0.1:8000
Contributing
We welcome contributions. See the Contributing Guide for development setup, branch and commit conventions, testing requirements, and the PR checklist.
Support
- Documentation: kanopi.github.io/firewall (source in
docs/) - Issues: github.com/kanopi/firewall/issues
- Discussions: github.com/kanopi/firewall/discussions
License
This project is licensed under the MIT License. See the LICENSE file for details.
Credits
Lite Firewall is developed and maintained by Kanopi Studios.
Special thanks to:
- The Symfony team for the excellent HttpFoundation component
- MaxMind for the GeoIP2 databases
- The Monolog team for the flexible logging library