# xzeroprotect
**Repository Path**: wfdaj/xzeroprotect
## Basic Information
- **Project Name**: xzeroprotect
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-06-08
- **Last Updated**: 2026-06-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
```
██╗ ██╗███████╗███████╗██████╗ ██████╗ ██████╗ ██████╗ ██████╗ ████████╗███████╗ ██████╗████████╗
╚██╗██╔╝╚══███╔╝██╔════╝██╔══██╗██╔═══██╗██╔══██╗██╔══██╗██╔═══██╗╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝
╚███╔╝ ███╔╝ █████╗ ██████╔╝██║ ██║██████╔╝██████╔╝██║ ██║ ██║ █████╗ ██║ ██║
██╔██╗ ███╔╝ ██╔══╝ ██╔══██╗██║ ██║██╔═══╝ ██╔══██╗██║ ██║ ██║ ██╔══╝ ██║ ██║
██╔╝ ██╗███████╗███████╗██║ ██║╚██████╔╝██║ ██║ ██║╚██████╔╝ ██║ ███████╗╚██████╗ ██║
╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝
```
**A lightweight, file-based PHP firewall for the modern web.**
No database. No external services. No compromises.
[](https://php.net)
[](https://packagist.org/packages/webrium/xzeroprotect)
[](LICENSE)
[]()
---
## Why xZeroProtect?
Every day, bots crawl your application looking for exposed `.env` files, WordPress admin panels, SQL injection vectors, and known CVEs — even if you're not running WordPress. xZeroProtect stops them at the PHP layer with zero external dependencies, no database connection, and a clean API you can tune in minutes.
- **File-based** — everything stored on disk; no MySQL, Redis, or memcached required
- **Zero dependencies** — pure PHP 8.0+, nothing else
- **Composable** — enable, disable, or extend every detection module independently
- **Learning mode** — log threats without blocking, perfect for tuning before going live
- **Apache-aware** — optionally write permanent bans into `.htaccess` so Apache rejects them before PHP even starts
---
## Installation
```bash
composer require webrium/xzeroprotect
```
---
## Quick Start
Add these two lines at the very top of your `index.php` or bootstrap file:
```php
run();
```
That's it. Default rules are active immediately.
> **Note:** `init()` stores the instance internally. You can retrieve it from anywhere in your application using `XZeroProtect::getInstance()` — no need to pass `$firewall` around.
---
## Configuration
Every option has a sensible default. Override only what you need:
```php
$firewall = XZeroProtect::init([
// 'production' → block & log | 'learning' → log only | 'off' → disabled
'mode' => 'production',
// Where ban files, rate data, and logs are stored
'storage_path' => __DIR__ . '/storage/firewall',
// --- Rate limiting ---
'rate_limit' => [
'enabled' => true,
'max_requests' => 60, // requests per window
'per_seconds' => 60, // window size in seconds
],
// --- Automatic banning ---
'auto_ban' => [
'enabled' => true,
'violations_threshold' => 10, // violations before a ban is issued
'ban_duration' => 86400, // ban length in seconds (24 h)
'permanent_after_bans' => 3, // escalate to permanent after N bans
],
// --- Apache integration ---
'apache_blocking' => false,
'htaccess_path' => __DIR__ . '/.htaccess',
// --- Always-allow list ---
'whitelist' => [
'ips' => ['127.0.0.1', '10.0.0.0/8'],
'paths' => ['/health', '/ping'],
],
// --- Response sent to blocked clients ---
'block_response' => [
'code' => 403,
'message' => 'Access Denied',
],
// --- Toggle individual detection modules ---
'checks' => [
'crawler_check' => true, // exempt verified crawlers from all checks
'rate_limit' => true,
'blocked_path' => true,
'user_agent' => true,
'payload' => true,
'custom_rules' => true,
],
// --- Log settings ---
'log' => [
'enabled' => true,
'max_file_size' => 10, // MB — auto-rotated when exceeded
'keep_days' => 30,
],
]);
$firewall->run();
```
---
## Detection Modules
### Path Detection
Blocks requests targeting sensitive or non-existent paths. Because a modern routed PHP app has no `.php` files in the URL, you can add that pattern to immediately reject the flood of `index.php?id=` scanner probes.
```php
// Add individual patterns
$firewall->patterns->addPath('.php');
$firewall->patterns->addPath('/control-panel');
// Add many at once
$firewall->patterns->addPaths(['.asp', '.jsp', '/backup', '/staging']);
// Remove a default pattern you want to allow
$firewall->patterns->removePath('xmlrpc');
```
View all default blocked paths
| Category | Patterns |
|----------|----------|
| CMS panels | `wp-admin`, `wp-login`, `wp-config`, `xmlrpc`, `administrator`, `typo3` |
| Config exposure | `.env`, `.git`, `.svn`, `.htaccess`, `.htpasswd`, `web.config` |
| DB tools | `phpmyadmin`, `pma`, `adminer`, `dbadmin` |
| Dangerous files | `.sql`, `.bak`, `.backup`, `.old`, `dump.sql` |
| Path traversal | `../`, `..%2f`, `%2e%2e` |
| Web shells | `shell.php`, `c99.php`, `r57.php`, `webshell` |
| Script extensions | `.asp`, `.aspx`, `.jsp`, `.cfm`, `.cgi` |
| Info disclosure | `phpinfo`, `server-status`, `server-info` |
| Install artifacts | `setup.php`, `install.php`, `readme.html` |
> **Note:** `.php` is **not** blocked by default to avoid false positives on applications that serve raw PHP files. Add it explicitly if your app uses modern routing: `$firewall->patterns->addPath('.php')`
---
### User-Agent Detection
Identifies and blocks known scanner, brute-force, and exploit tool signatures. Empty User-Agent strings are treated as suspicious by default.
```php
$firewall->patterns->addAgent('custom-bad-bot');
$firewall->patterns->removeAgent('curl'); // allow curl if your API clients use it
```
View default blocked agents
`sqlmap` · `nikto` · `nessus` · `acunetix` · `netsparker` · `masscan` · `nmap` · `zgrab` · `dirbuster` · `gobuster` · `feroxbuster` · `wfuzz` · `ffuf` · `hydra` · `metasploit` · `semrushbot` · `ahrefsbot` · `libwww-perl` · and more
> **Note:** `curl`, `wget`, `python-requests`, and `go-http-client` are **not** blocked by default because they are also used by legitimate API clients. Add them explicitly if needed:
> ```php
> $firewall->patterns->addAgent('curl/');
> $firewall->patterns->addAgent('wget/');
> $firewall->patterns->addAgent('python-requests');
> $firewall->patterns->addAgent('go-http-client');
> ```
---
### Payload Detection
Scans GET parameters, POST body, raw input, and cookies for attack signatures using compiled regular expressions.
```php
// Add a custom pattern
$firewall->patterns->addPayload('/CUSTOM_EXPLOIT/i', 'my_label');
// Remove a built-in pattern
$firewall->patterns->removePayload('sqli_union');
```
View default payload rules
| Label | Detects |
|-------|---------|
| `sqli_union` | `UNION [ALL] SELECT` |
| `sqli_select` | `SELECT ... FROM` |
| `sqli_drop` | `DROP TABLE/DATABASE` |
| `sqli_sleep` | `SLEEP(n)` time-based blind |
| `sqli_benchmark` | `BENCHMARK(...)` |
| `sqli_comment` | `--`, `#`, `/* */` injection comments |
| `xss_script` | `