-
-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Get up and running with Laravel Safeguard in just a few minutes! This guide will walk you through installing the package and running your first security check.
composer require --dev grazulex/laravel-safeguard
php artisan vendor:publish --tag=safeguard-config
Already installed? Skip to Your First Security Check
Run a basic security audit:
php artisan safeguard:check
Example Output:
π Laravel Safeguard Security Check
βββββββββββββββββββββββββββββββββββββββ
Environment: local
β
APP_KEY is set
β
Storage directories are writable
β
CSRF protection enabled
β οΈ APP_DEBUG is enabled (acceptable in local environment)
βββββββββββββββββββββββββββββββββββββββ
π― All checks passed! (4 checks)
Laravel Safeguard uses clear icons to show the status of each security check:
- β Green checkmark: Rule passed successfully
- β Red X: Rule failed (needs immediate attention)
β οΈ Yellow warning: Rule has warnings (review recommended)- π¨ Red alert: Critical security issue found
See what security rules are available:
php artisan safeguard:list
Output:
π‘οΈ Available Security Rules:
βββββββββββββββββββββββββββββββββββββββ
Environment & Configuration:
β app-debug-false-in-production
β env-has-all-required-keys
β app-key-is-set
β no-secrets-in-code
Security Rules:
β csrf-enabled
β composer-package-security
...
Run checks for production environment:
php artisan safeguard:check --env=production
Get machine-readable output for scripts and CI/CD:
php artisan safeguard:check --format=json
Edit config/safeguard.php
to customize your security rules:
return [
'rules' => [
// π Essential security rules (recommended to keep enabled)
'app-key-is-set' => true,
'app-debug-false-in-production' => true,
'csrf-enabled' => true,
// π‘οΈ Optional rules (enable based on your needs)
'no-secrets-in-code' => true,
'env-file-permissions' => true,
'database-connection-encrypted' => false, // Enable for production
],
// π― Environment-specific rules
'environments' => [
'production' => [
'app-debug-false-in-production',
'app-key-is-set',
'env-file-permissions',
'database-connection-encrypted',
],
'local' => [
'app-key-is-set',
'csrf-enabled',
],
],
];
Here's what a typical security check might reveal in a production environment:
php artisan safeguard:check --env=production
π Laravel Safeguard Security Check
βββββββββββββββββββββββββββββββββββββββ
Environment: production
β
APP_KEY is set
β APP_DEBUG is true in production
β
CSRF protection enabled
β Secret found in config/services.php (STRIPE_SECRET)
β
Storage directories are writable
β οΈ HTTPS not enforced (rule disabled)
βββββββββββββββββββββββββββββββββββββββ
π― 2 issues found, 4 checks passed
-
APP_DEBUG issue: Set
APP_DEBUG=false
in your production.env
-
Hardcoded secret: Move
STRIPE_SECRET
to environment variables:// Before (config/services.php): 'stripe' => [ 'secret' => 'sk_live_xxxxxxxxxxxx', // β Hardcoded ], // After (config/services.php): 'stripe' => [ 'secret' => env('STRIPE_SECRET'), // β Environment variable ], // Add to .env: STRIPE_SECRET=sk_live_xxxxxxxxxxxx
Add to .github/workflows/security.yml
:
name: Security Audit
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- name: Install dependencies
run: composer install --no-dev --optimize-autoloader
- name: Run security checks
run: php artisan safeguard:check --env=production --fail-on-error
Create a deployment checklist script:
#!/bin/bash
echo "π Running pre-deployment security checks..."
php artisan safeguard:check --env=production --fail-on-error
if [ $? -eq 0 ]; then
echo "β
Security checks passed! Safe to deploy."
else
echo "β Security issues found! Please fix before deploying."
exit 1
fi
Make it executable and use it:
chmod +x scripts/security-check.sh
./scripts/security-check.sh
Now that you have Laravel Safeguard running, explore these features:
Beginner Path:
- βοΈ Configuration Guide - Learn to configure rules for your needs
- π‘ Examples Collection - See real-world usage examples
- π Rules Reference - Understand all available security rules
Intermediate Path:
- π CI/CD Integration - Automate security checks
- π Environment Rules - Environment-specific configurations
- π Output Formats - Customize output for different tools
Advanced Path:
- ποΈ Custom Rules - Create application-specific security rules
- π API Reference - Programmatic usage
- β‘ Performance - Optimize for large applications
If the safeguard:check
command doesn't work:
# Check if package is installed
composer show grazulex/laravel-safeguard
# Check if commands are available
php artisan list | grep safeguard
Make sure you've published the configuration:
php artisan vendor:publish --tag=safeguard-config --force
Check your config/safeguard.php
file has rules set to true
:
'rules' => [
'app-key-is-set' => true, // β Make sure this is true
'csrf-enabled' => true, // β And this
// ...
],
Ensure Laravel can write to required directories:
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/
- β FAQ - Common questions and answers
- π Troubleshooting - Solutions to common problems
- GitHub Issues - Report bugs or request features
Next Step: βοΈ Configure security rules for your application
π Home | π¦ Installation | βοΈ Configuration | π‘ Examples
Laravel Safeguard - Configurable Security Checks for Laravel Applications
π Home | π¦ Installation | β‘ Quick Start | π‘ Examples | π Full Docs
Made with β€οΈ for the Laravel community
Β© 2025 - Laravel Safeguard by Grazulex