swayok / laravel-antihack-tool
Active anti-hack protection for Laravel
Installs: 80
Dependents: 0
Suggesters: 1
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/swayok/laravel-antihack-tool
Requires
- php: >=5.5
- laravel/framework: >=5.3|>=6.0
This package is auto-updated.
Last update: 2025-10-10 10:07:00 UTC
README
This is active anti-hack protection tool that will guard your project from most hack attempts that use HTTP requests. It also contains whitelist and blacklist functionality based on config files or database table contents
Installation
Add "swayok/laravel-antihack-tool": "master-dev" to your composer.json
into require section and run composer update
Activation
For Laravale 5.5+
Service provider will be automatically loaded
For Laravel 5.4-
Add LaravelAntihackTool\AntihackServiceProvider to yor app.providers config
Add section to your CMF section
Add \LaravelAntihackTool\PeskyCmf\CmfHackAttempts\CmfHackAttemptsScaffoldConfig::class
to your cmf section's config (probably config/admin.php) into 'resources' key:
'resources' => [
\LaravelAntihackTool\PeskyCmf\CmfHackAttempts\CmfHackAttemptsScaffoldConfig::class
}
Configuration
-
Run
php artisan vendor:publish --provider=LaravelAntihackTool\AntihackServiceProviderto publish configuration file -
If you plan to use database to store hack attempts - set
antihack.store_hack_attemptsconfiguration paramenter totrueand modifyantihack.connectionandantihack.table_nameconfiguration paramenters if needed. Then runphp artisan antihack:installand confirm migration task. On production server you will need to run migration manually usingphp artisan migratecommand. -
If you're using PeskyCmf or PeskyCms - you may need to add a menu item for resource in your
menu()method of yourAdminConfigclass (or other class that extendsCmfConfigclass). Menu item:static::getMenuItem('hack_attempts')or your custom one. -
On development server you may need to set
antihack.allow_localhost_iptotruein order to allow requests from127.0.0.1ip. By default this option is set totrueforlocalenvironment and tofalsefor any other environments. -
I you use any urls that have
.phpextensions - setantihack.allow_php_extension_in_urltotrue. -
Whitelists and blacklists are generated automatically and cached to your default cache provider. You may change cache key and duration configuration paramenters if you need. Also you may update cache using
php artisan antihack:blacklistmanually. -
There are 2 error templates in this package:
'antihack::errors.406'(hack detected) and'antihack::errors.423'(ip or user agent is blacklisted/banned). In Laravel 5.5+ you will need to modify yourApp\Exceptions\Handlerclass like this to use them:public function prepareResponse($request, Exception $exception) { if ($exception instanceof \LaravelAntihackTool\Exception\AntihackException) { return response()->view('antihack::errors.' . $exception->getStatusCode()); } return parent::prepareResponse($request, $exception); }