-
-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
Welcome to the Laravel Safeguard FAQ! Here you'll find answers to the most common questions about installation, configuration, usage, and troubleshooting.
Laravel Safeguard is a configurable security audit package for Laravel applications. It acts like Pint, PHPStan, or Rector but for security and configuration auditing. It helps identify security issues, misconfigurations, and potential vulnerabilities before they reach production.
Common production issues that Laravel Safeguard helps prevent:
- β Missing critical variables (APP_KEY, DB_PASSWORD, etc.)
- π Hardcoded secrets in code instead of environment variables
- π¨ Inconsistencies between
.env.example
and.env
β οΈ Security misconfigurations (APP_DEBUG=true in production)- π Insecure defaults that should be changed before going live
Laravel Safeguard focuses specifically on configuration and environment security rather than code vulnerability scanning. It's complementary to tools like:
Tool | Focus | Laravel Safeguard |
---|---|---|
PHPStan | Static code analysis | β Configuration auditing |
Psalm | Type checking | β Environment validation |
Security scanners | Code vulnerabilities | β Security misconfigurations |
Pint | Code formatting | β Security standards |
Yes! Laravel Safeguard is open source and completely free to use in both personal and commercial projects.
Yes, but we recommend installing it as a development dependency (--dev
) since it's primarily used for auditing and CI/CD processes:
composer require --dev grazulex/laravel-safeguard
Publishing the configuration is optional but recommended for customization:
php artisan vendor:publish --tag=safeguard-config
Without publishing, Laravel Safeguard will use sensible defaults.
Laravel Safeguard requires:
- PHP: 8.3 or higher
- Laravel: 12.19 or higher
The current version is designed for Laravel 12.x. For older Laravel versions, you may need to:
- Use an older version of the package
- Manually adapt the configuration
- Check compatibility with your specific Laravel version
Laravel Safeguard is primarily designed for full Laravel applications. While some features might work with Lumen, it's not officially supported.
Edit config/safeguard.php
:
'rules' => [
'app-key-is-set' => true, // β
Enabled
'https-enforced-in-production' => false, // β Disabled
'csrf-enabled' => true, // β
Enabled
],
Yes! Use environment-specific configuration:
'environments' => [
'production' => [
'app-debug-false-in-production',
'secure-cookies-in-production',
'https-enforced-in-production',
'database-connection-encrypted',
],
'staging' => [
'app-debug-false-in-production',
'csrf-enabled',
],
'local' => [
'app-key-is-set',
'storage-writable',
],
],
Customize the secret_patterns
array in your configuration:
'secret_patterns' => [
'*_KEY',
'*_SECRET',
'*_TOKEN',
'*_PASSWORD',
'MY_CUSTOM_*',
'COMPANY_API_*',
'STRIPE_*',
'AWS_*',
],
Currently, you can specify which paths to scan. To exclude paths, simply don't include them in scan_paths
:
'scan_paths' => [
'app/',
'config/',
'routes/',
// 'tests/' - excluded by not listing it
// 'vendor/' - excluded by not listing it
],
Adjust performance settings in your configuration:
'performance' => [
'max_scan_files' => 10000,
'timeout_seconds' => 300,
'memory_limit' => '512M',
'parallel_processing' => true,
],
-
--env=production
: Sets the environment context but runs all enabled rules -
--env-rules
: Uses only the rules defined for that specific environment
# Runs all enabled rules with production context
php artisan safeguard:check --env=production
# Runs only production-specific rules
php artisan safeguard:check --env=production --env-rules
Use the --severity
option:
# Only critical issues
php artisan safeguard:check --severity=critical
# Critical and error level issues
php artisan safeguard:check --severity=critical,error
Yes, use the --rules
option:
php artisan safeguard:check --rules=app-key-is-set,csrf-enabled
Laravel Safeguard supports multiple output formats:
# CLI format (default, human-readable)
php artisan safeguard:check
# JSON format (machine-readable)
php artisan safeguard:check --format=json
# CI format (no colors, CI-friendly)
php artisan safeguard:check --format=ci
# JUnit XML format (for test integration)
php artisan safeguard:check --format=junit
# HTML format (for reports)
php artisan safeguard:check --format=html
Use the --fail-on-error
flag:
php artisan safeguard:check --fail-on-error
This will exit with code 1
if any security issues are found, causing your CI/CD pipeline to fail.
Use the artisan command to generate a new rule:
php artisan safeguard:make-rule MyCustomRule
This creates a new rule class that you can customize:
<?php
namespace App\SafeguardRules;
use Grazulex\LaravelSafeguard\Contracts\SafeguardRule;
use Grazulex\LaravelSafeguard\SafeguardResult;
class MyCustomRule implements SafeguardRule
{
public function id(): string
{
return 'my-custom-rule';
}
public function check(): SafeguardResult
{
// Your custom logic here
return SafeguardResult::pass('Custom check passed');
}
// ... other required methods
}
By default, custom rules go in app/SafeguardRules/
. You can customize this path:
// config/safeguard.php
'custom_rules_path' => app_path('Security/Rules'),
'custom_rules_namespace' => 'App\\Security\\Rules',
Add them to your configuration:
'rules' => [
// Built-in rules
'app-key-is-set' => true,
// Your custom rules
'my-custom-rule' => true,
'another-custom-rule' => false,
],
Yes! You can organize rules by category:
app/SafeguardRules/
βββ Authentication/
β βββ PasswordPolicyRule.php
β βββ TwoFactorRule.php
βββ Database/
β βββ DatabaseSecurityRule.php
βββ Api/
βββ ApiSecurityRule.php
Create .github/workflows/security.yml
:
name: Security Checks
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
- name: Run security checks
run: php artisan safeguard:check --fail-on-error
Add to .gitlab-ci.yml
:
security_check:
stage: test
image: php:8.3-cli
script:
- composer install
- php artisan safeguard:check --fail-on-error --format=junit > security.xml
artifacts:
reports:
junit: security.xml
Yes, but consider a progressive approach:
- Pull Requests: Run all security checks
- Development branches: Run critical checks only
- Main branch: Run comprehensive security audit
# For development branches
php artisan safeguard:check --severity=critical --fail-on-error
# For production deployments
php artisan safeguard:check --env=production --fail-on-error
Several optimization strategies:
- Limit scan paths:
'scan_paths' => [
'app/',
'config/',
// Remove 'vendor/', 'node_modules/', etc.
],
- Reduce file scan limits:
'performance' => [
'max_scan_files' => 5000, // Reduce from default
'timeout_seconds' => 120,
],
- Enable parallel processing:
'performance' => [
'parallel_processing' => true,
],
- Use rule caching:
php artisan safeguard:cache rebuild
Yes:
php artisan safeguard:check --severity=critical
Memory usage depends on your project size. For most projects, it uses 50-200MB. For large projects, you can increase the memory limit:
'performance' => [
'memory_limit' => '1G', // Increase if needed
],
If you get a "Command not found" error:
- Check if the package is installed:
composer show grazulex/laravel-safeguard
- Check if commands are available:
php artisan list | grep safeguard
- Clear Laravel caches:
php artisan config:clear
php artisan cache:clear
Make sure you've published the configuration:
php artisan vendor:publish --tag=safeguard-config --force
- Check rule configuration:
// Make sure rules are enabled
'rules' => [
'app-key-is-set' => true, // Should be true
],
- Verify custom rules path:
'custom_rules_path' => app_path('SafeguardRules'),
'custom_rules_namespace' => 'App\\SafeguardRules',
- Check rule class implementation:
// Must implement SafeguardRule interface
class MyRule implements SafeguardRule
{
// Required methods must be implemented
}
- Reduce scan scope:
'scan_paths' => [
'app/', // Only scan essential directories
'config/',
],
- Increase timeouts:
'performance' => [
'timeout_seconds' => 600, // 10 minutes
'max_scan_files' => 20000,
],
- Use file patterns to exclude large files:
# In your CI script
find . -name \"*.log\" -delete # Remove log files
find . -name \"node_modules\" -type d -exec rm -rf {} + # Remove node_modules
Configure more specific patterns or exclusions:
'secret_patterns' => [
'*_KEY',
'*_SECRET',
'!TEST_*', // Exclude test-related patterns
'!MOCK_*', // Exclude mock data
],
Yes, but install it as a dev dependency. Laravel Safeguard only reads your configuration and code - it doesn't modify anything.
No. Laravel Safeguard runs entirely locally and doesn't send any data externally.
Laravel Safeguard is designed to detect sensitive information, not expose it. However:
- Be careful with output logs in CI/CD
- Don't commit security reports with sensitive data
- Use appropriate log retention policies
You can:
- Update patterns to be more specific
- Use exclusion patterns for test data
- Move test secrets to dedicated test files
- Use environment variables even for test data
Recommended frequency:
- β Every commit (via CI/CD)
- β Before deployments (mandatory)
- β Weekly reports (comprehensive audit)
- β Before major releases (full security review)
Start with critical rules:
app-key-is-set
app-debug-false-in-production
csrf-enabled
no-secrets-in-code
Then add environment-specific rules:
5. secure-cookies-in-production
6. env-file-permissions
7. database-connection-encrypted
Progressive approach:
- Block deployment on critical issues
- Warn but continue on medium issues
- Report but allow informational issues
# Critical issues block deployment
php artisan safeguard:check --severity=critical --fail-on-error
# Medium issues create warnings
php artisan safeguard:check --severity=error || echo \"Warning: Security issues found\"
# Full report for review
php artisan safeguard:check --format=json > security-report.json
If you can't find the answer to your question:
- π Check the documentation: Wiki Home
- π Search issues: GitHub Issues
- π¬ Ask the community: GitHub Discussions
- π Report bugs: New Issue
Didn't find what you're looking for? Check the π Troubleshooting Guide for more detailed solutions.
π Home | β‘ Quick Start | π Troubleshooting | π Documentation
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