composer require artflow-studio/laravel-security
The package will auto-register via Laravel's package discovery.
# Publish console security config
php artisan vendor:publish --tag=console-security-config
# Publish JavaScript assets (required)
php artisan vendor:publish --tag=console-security-assets
# (Optional) Publish views for customization
php artisan vendor:publish --tag=console-security-views
In your main layout file (e.g., resources/views/layouts/app.blade.php):
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{ csrf_token() }}">
{{-- Add this single line --}}
[@afConsoleSecurity](https://github.com/afConsoleSecurity)
{{-- Your other head content --}}
</head>
In your routes/web.php:
use Illuminate\Support\Facades\Route;
// Protected routes (admin, dashboard, sensitive pages)
Route::middleware(['console:strict'])->group(function () {
Route::get('/admin', [AdminController::class, 'index']);
Route::get('/dashboard', [DashboardController::class, 'index']);
Route::resource('users', UserController::class);
});
// Public routes (no protection needed)
Route::get('/', [HomeController::class, 'index']);
Route::get('/about', [PageController::class, 'about']);
That's it! Your application is now protected. ๐
The package automatically detects when users open browser DevTools using multiple methods:
When DevTools is detected, users are redirected to a friendly "blocked" page and can return when they close DevTools.
Every request is validated with an encrypted, session-bound token:
The JavaScript shield prevents:
For Livewire components, use the WithConsoleSecurity trait:
use ArtflowStudio\LaravelSecurity\Traits\WithConsoleSecurity;
use Livewire\Component;
class UserProfile extends Component
{
use WithConsoleSecurity;
public $name;
public $email;
// Automatically protected from:
// - SQL injection attempts
// - XSS attacks
// - Property manipulation via console
// - Excessive requests
}
Edit config/console-security.php to customize behavior:
return [
// Enable/disable the entire module
'enabled' => env('CONSOLE_SECURITY_ENABLED', true),
// Cookie settings
'cookie' => [
'name' => 'af_handshake',
'lifetime' => 5, // minutes
'secure' => true, // HTTPS only
],
// Token settings
'token' => [
'auto_renew' => true, // Prevent 419 errors
'rotation_interval' => 240, // 4 minutes
'grace_period' => 60, // 1 minute
],
];
Paths that should bypass security checks:
'excluded_paths' => [
'api/*', // API routes
'assets/*', // Static assets
'livewire/*', // Livewire internal routes
'_security/*', // Security handshake routes
],
Allow specific IPs to bypass checks (useful for development):
'whitelist' => [
'ips' => ['127.0.0.1', '192.168.1.0/24'],
'user_agents' => ['Googlebot', 'Lighthouse'],
],
Fine-tune detection thresholds:
'detection' => [
'size_threshold' => 160, // pixels
'timing_threshold' => 120, // milliseconds
'loop_iterations' => 100000, // performance test
],
After publishing views, customize the loader and blocked pages:
php artisan vendor:publish --tag=console-security-views
Edit:
resources/views/vendor/laravel-security/loader.blade.phpresources/views/vendor/laravel-security/blocked.blade.phpAfter publishing assets, customize the detection logic:
php artisan vendor:publish --tag=console-security-assets
Edit:
public/vendor/laravel-security/js/console-security.jsDisable console security during development:
# .env
CONSOLE_SECURITY_ENABLED=false
Or whitelist your IP:
CONSOLE_SECURITY_WHITELIST_IPS=127.0.0.1,192.168.1.100
Add debugging badge to your layout:
{{-- Shows token status, expiry, etc. (only in debug mode) --}}
[@afSecurityStatus](https://github.com/afSecurityStatus)
{{-- Shows "Protected by Laravel Security" badge --}}
[@afSecurityBadge](https://github.com/afSecurityBadge)
Check token status via JavaScript console:
// Check if DevTools are detected
AF_SECURITY.detectDevTools()
// Manually renew token
AF_SECURITY.renewToken()
// Get token status
fetch('/_security/handshake/status')
.then(r => r.json())
.then(console.log)
If you see 419 errors, ensure:
csrf-token meta tag is present in your layout'auto_renew' => true in configIf stuck on loader page:
/_security/handshake/verifySESSION_DRIVER in .env)storage/logs/laravel.logIf legitimate users are blocked:
If using the trait and still having issues:
use WithConsoleSecurity;composer update livewire/livewirephp artisan livewire:discoverSecurity events are logged to your configured log channel:
# View recent security logs
tail -f storage/logs/laravel.log | grep "Console Security"
The package logs:
The security cookie requires HTTPS in production:
// config/console-security.php
'cookie' => [
'secure' => env('APP_ENV') === 'production',
],
Shorter token lifetimes = smaller attack window:
'cookie' => [
'lifetime' => 5, // 5 minutes
],
'token' => [
'rotation_interval' => 240, // 4 minutes
],
Only whitelist trusted IPs:
'whitelist' => [
'ips' => [
'127.0.0.1', // Local development only
],
],
Regularly review security logs for patterns:
# Count blocked attempts per IP
grep "blocked" storage/logs/laravel.log | awk '{print $10}' | sort | uniq -c | sort -rn
Test security in staging before production:
use ArtflowStudio\LaravelSecurity\Support\SecurityToken;
// Generate new token
$token = SecurityToken::generate();
// Verify token
$valid = SecurityToken::verify($token['encrypted']);
// Check if expiring soon
$expiring = SecurityToken::isExpiring();
// Get metadata
$metadata = SecurityToken::metadata();
Create your own middleware for specific logic:
use ArtflowStudio\LaravelSecurity\Http\Middleware\ConsoleStrictMiddleware;
class MyCustomSecurityMiddleware extends ConsoleStrictMiddleware
{
protected function isExcludedPath($request): bool
{
// Custom exclusion logic
if ($request->is('my-special-path/*')) {
return true;
}
return parent::isExcludedPath($request);
}
}
Protect specific Blade sections:
[@requiresHandshake](https://github.com/requiresHandshake)
<div>This content only shows if handshake is valid</div>
<p>Sensitive data here...</p>
[@endrequiresHandshake](https://github.com/endrequiresHandshake)
Total: <1% impact for most applications
PLAN.md for detailed architectureHaving issues? Try these resources:
config/console-security.phpstorage/logs/laravel.logCongratulations! ๐ Your Laravel application is now protected with enterprise-grade console security.
Remember: This is defense in depth. Always validate data server-side, use proper authentication, and follow Laravel security best practices.
How can I help you explore Laravel packages today?