-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commands
Laravel Safeguard provides several artisan commands for running security checks, managing rules, and generating reports. This comprehensive guide covers all available commands and their options.
Run security checks on your Laravel application.
php artisan safeguard:check [options]
Option | Description | Example | Default |
---|---|---|---|
--env=ENVIRONMENT |
Specify environment to check | --env=production |
Current environment |
--format=FORMAT |
Output format (cli, json, html, junit) | --format=json |
cli |
--fail-on-error |
Exit with error code if rules fail | --fail-on-error |
false |
--ci |
CI-friendly output (no colors) | --ci |
false |
--env-rules |
Use environment-specific rules only | --env-rules |
false |
--severity=LEVEL |
Run only rules with specific severity | --severity=critical |
All severities |
--rules=RULES |
Run only specific rules | --rules=app-key-is-set,csrf-enabled |
All enabled rules |
--verbose |
Show detailed output | --verbose |
false |
--quiet |
Suppress output (except errors) | --quiet |
false |
# π Basic security check
php artisan safeguard:check
# π Check specific environment
php artisan safeguard:check --env=production
# π― Use only environment-specific rules
php artisan safeguard:check --env=production --env-rules
# π Get JSON output for automation
php artisan safeguard:check --format=json
# π CI/CD usage (no colors, fail on error)
php artisan safeguard:check --ci --fail-on-error
# π¨ Check only critical issues
php artisan safeguard:check --severity=critical --fail-on-error
# π― Run specific rules only
php artisan safeguard:check --rules=app-key-is-set,csrf-enabled
# π Detailed output with recommendations
php artisan safeguard:check --verbose
# π Silent mode (errors only)
php artisan safeguard:check --quiet --fail-on-error
-
0
: All checks passed successfully -
1
: One or more checks failed (only when using--fail-on-error
) -
2
: Configuration error or invalid arguments
CLI Format (default):
π Laravel Safeguard Security Check
βββββββββββββββββββββββββββββββββββββββ
Environment: production
β
APP_KEY is set
β
CSRF protection enabled
β APP_DEBUG is enabled in production
β οΈ Database connection not encrypted
βββββββββββββββββββββββββββββββββββββββ
π― 2 issues found, 2 checks passed
JSON Format:
{
\"status\": \"failed\",
\"environment\": \"production\",
\"timestamp\": \"2025-01-01T10:00:00Z\",
\"checks\": [
{
\"rule\": \"app-key-is-set\",
\"status\": \"passed\",
\"severity\": \"critical\",
\"message\": \"APP_KEY is properly set\"
},
{
\"rule\": \"app-debug-false-in-production\",
\"status\": \"failed\",
\"severity\": \"critical\",
\"message\": \"APP_DEBUG is enabled in production\",
\"recommendations\": [\"Set APP_DEBUG=false in production .env file\"]
}
],
\"summary\": {
\"total\": 10,
\"passed\": 8,
\"failed\": 1,
\"warnings\": 1
}
}
Display all available security rules and their current status.
php artisan safeguard:list [options]
Option | Description | Example | Default |
---|---|---|---|
--enabled |
Show only enabled rules | --enabled |
Show all |
--disabled |
Show only disabled rules | --disabled |
Show all |
--environment=ENV |
Show rules for specific environment | --environment=production |
All environments |
--severity=LEVEL |
Show rules with specific severity | --severity=critical |
All severities |
--format=FORMAT |
Output format (table, json, csv) | --format=json |
table |
--filter=PATTERN |
Filter rules by name pattern | --filter=database |
No filter |
# π List all rules
php artisan safeguard:list
# β
List only enabled rules
php artisan safeguard:list --enabled
# β List only disabled rules
php artisan safeguard:list --disabled
# π List rules for specific environment
php artisan safeguard:list --environment=production
# π¨ List critical rules only
php artisan safeguard:list --severity=critical
# π JSON output for automation
php artisan safeguard:list --format=json
# π Filter rules by pattern
php artisan safeguard:list --filter=database
# π CSV export
php artisan safeguard:list --format=csv > rules-export.csv
ββββββββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ
β Rule ID β Status β Severity β Description β
ββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββ€
β app-key-is-set β β
On β critical β Verifies that Laravel application... β
β app-debug-false-in-production β β
On β critical β Ensures APP_DEBUG is false in... β
β csrf-enabled β β
On β critical β Ensures CSRF protection is enabled β
β no-secrets-in-code β β
On β critical β Detects hardcoded secrets in... β
β database-connection-encrypted β β
On β critical β Verifies database connections... β
β password-policy-compliance β β
On β critical β Verifies password policy meets... β
β two-factor-auth-enabled β β Off β warning β Validates two-factor auth config... β
ββββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ
π Summary: 6 enabled, 1 disabled (7 total rules)
Test individual security rules in isolation.
php artisan safeguard:test-rule <rule-id> [options]
Argument | Description | Required |
---|---|---|
rule-id |
The ID of the rule to test | Yes |
Option | Description | Example | Default |
---|---|---|---|
--env=ENVIRONMENT |
Environment context for testing | --env=production |
Current environment |
--verbose |
Show detailed test output | --verbose |
false |
--format=FORMAT |
Output format (cli, json) | --format=json |
cli |
# π§ͺ Test a specific rule
php artisan safeguard:test-rule app-debug-false-in-production
# π Test rule in specific environment context
php artisan safeguard:test-rule database-connection-encrypted --env=production
# π Detailed test output
php artisan safeguard:test-rule no-secrets-in-code --verbose
# π JSON output for automation
php artisan safeguard:test-rule csrf-enabled --format=json
π§ͺ Testing Rule: app-debug-false-in-production
βββββββββββββββββββββββββββββββββββββββββββββββ
Environment: production
Severity: critical
β
Rule passed: APP_DEBUG is properly disabled in production
Execution time: 15ms
Memory usage: 2.1MB
Generate a new custom security rule.
php artisan safeguard:make-rule <name> [options]
Argument | Description | Required |
---|---|---|
name |
Name of the rule class | Yes |
Option | Description | Example | Default |
---|---|---|---|
--path=PATH |
Custom path for the rule | --path=app/Security/Rules |
app/SafeguardRules |
--namespace=NAMESPACE |
Custom namespace | --namespace=App\\Security\\Rules |
App\\SafeguardRules |
--severity=LEVEL |
Default severity level | --severity=critical |
error |
--template=TYPE |
Rule template type | --template=database |
basic |
# ποΈ Create a basic custom rule
php artisan safeguard:make-rule CustomSecurityRule
# π Create rule with custom path and namespace
php artisan safeguard:make-rule ApiSecurityRule \\
--path=app/Security/Rules \\
--namespace=App\\Security\\Rules
# π¨ Create critical rule with template
php artisan safeguard:make-rule DatabaseSecurityRule \\
--severity=critical \\
--template=database
ποΈ Creating custom security rule...
β
Rule created successfully!
File: app/SafeguardRules/CustomSecurityRule.php
Namespace: App\\SafeguardRules
Next steps:
1. Implement the check() method
2. Add the rule to your config/safeguard.php
3. Test your rule with: php artisan safeguard:test-rule custom-security-rule
Generate comprehensive security reports.
php artisan safeguard:report [options]
Option | Description | Example | Default |
---|---|---|---|
--format=FORMAT |
Report format (html, pdf, json, csv) | --format=html |
html |
--output=FILE |
Output file path | --output=reports/security.html |
Auto-generated |
--env=ENVIRONMENT |
Environment to report on | --env=production |
All environments |
--template=TEMPLATE |
Report template | --template=executive |
detailed |
--include-passed |
Include passed checks in report | --include-passed |
false |
--email=EMAIL |
Email report to address | [email protected] |
No email |
# π Generate HTML report
php artisan safeguard:report --format=html
# π§ Generate and email PDF report
php artisan safeguard:report --format=pdf [email protected]
# π Production environment report
php artisan safeguard:report --env=production --output=prod-security-report.html
# π Executive summary report
php artisan safeguard:report --template=executive --format=pdf
# π Complete CSV export
php artisan safeguard:report --format=csv --include-passed --output=complete-audit.csv
Manage security rule caching for improved performance.
php artisan safeguard:cache [action] [options]
Action | Description | Example |
---|---|---|
clear |
Clear security rule cache | php artisan safeguard:cache clear |
rebuild |
Rebuild security rule cache | php artisan safeguard:cache rebuild |
status |
Show cache status | php artisan safeguard:cache status |
# ποΈ Clear cache
php artisan safeguard:cache clear
# π Rebuild cache
php artisan safeguard:cache rebuild
# π Check cache status
php artisan safeguard:cache status
Manage Safeguard configuration.
php artisan safeguard:config [action] [options]
Action | Description | Example |
---|---|---|
show |
Display current configuration | php artisan safeguard:config show |
validate |
Validate configuration file | php artisan safeguard:config validate |
export |
Export configuration | php artisan safeguard:config export |
Option | Description | Example | Default |
---|---|---|---|
--format=FORMAT |
Output format (json, yaml, php) | --format=json |
json |
--output=FILE |
Output file path | --output=config-export.json |
STDOUT |
# π Show current configuration
php artisan safeguard:config show
# β
Validate configuration
php artisan safeguard:config validate
# π Export configuration as JSON
php artisan safeguard:config export --format=json --output=safeguard-config.json
# Run multiple commands in sequence
php artisan safeguard:check --env=staging --fail-on-error && \\
php artisan safeguard:check --env=production --fail-on-error && \\
php artisan safeguard:report --format=html --output=weekly-report.html
# Only generate report if checks pass
php artisan safeguard:check --quiet --fail-on-error && \\
php artisan safeguard:report --format=pdf [email protected]
#!/bin/bash
# scripts/comprehensive-security-audit.sh
echo \"π Starting comprehensive security audit...\"
# Test individual critical rules first
for rule in \"app-key-is-set\" \"app-debug-false-in-production\" \"csrf-enabled\"; do
php artisan safeguard:test-rule $rule --env=production
if [ $? -ne 0 ]; then
echo \"β Critical rule $rule failed\"
exit 1
fi
done
# Run full security check
php artisan safeguard:check --env=production --fail-on-error
# Generate reports
php artisan safeguard:report --env=production --format=html --output=security-report.html
php artisan safeguard:report --env=production --format=json --output=security-data.json
echo \"β
Security audit completed successfully\"
Add --verbose
to any command for detailed debugging information:
php artisan safeguard:check --verbose
php artisan safeguard:test-rule app-key-is-set --verbose
Enable Laravel's debug mode for additional debugging:
APP_DEBUG=true php artisan safeguard:check --verbose
# Check if configuration is valid
php artisan safeguard:config validate
# Show current configuration
php artisan safeguard:config show
# List all available rules
php artisan safeguard:list --format=json
# Use appropriate flags for automation
php artisan safeguard:check --ci --fail-on-error --format=json
# Use environment-specific rules for accurate results
php artisan safeguard:check --env=production --env-rules
# Start with critical issues, then expand
php artisan safeguard:check --severity=critical --fail-on-error
# Schedule regular comprehensive reports
php artisan safeguard:report --format=html [email protected]
# Use caching for better performance
php artisan safeguard:cache rebuild
- β‘ Quick Start - Get started with basic commands
- βοΈ Configuration - Configure command behavior
- π CI/CD Integration - Use commands in pipelines
- π Output Formats - Understand different output formats
- π Troubleshooting - Solve command-related issues
Next Step: π Learn about output formats
π Home | β‘ Quick Start | βοΈ Configuration | π Output Formats
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