Installation:
composer require sensiolabs/security-checker --dev
Add to composer.json under require-dev to ensure it runs only in development.
First Run:
vendor/bin/security-checker security:check
This scans your project for known vulnerabilities in dependencies (via security.symfony.com).
Laravel-Specific Use Case:
Run in your Laravel project root to check composer.lock for outdated/unsafe packages. Example output:
[OK] Your requirements are satisfied
or
[WARNING] Found 2 vulnerabilities
Where to Look:
--format=json flag for programmatic use (e.g., CI integration).CI/CD Integration:
Add to .github/workflows/security.yml:
- name: Security Check
run: vendor/bin/security-checker security:check --format=json > security.json
Fail the build on warnings/errors.
Laravel-Specific:
post-test or pre-deploy scripts to block vulnerable releases.composer outdated to prioritize secure updates:
composer outdated && vendor/bin/security-checker security:check
Programmatic Use: Parse JSON output to trigger alerts (e.g., Slack notifications):
$output = shell_exec('vendor/bin/security-checker security:check --format=json');
$data = json_decode($output, true);
if (isset($data['vulnerable'])) {
// Notify team
}
Custom Scripts:
Combine with Laravel’s Artisan for automated checks:
// app/Console/Commands/CheckSecurity.php
public function handle() {
$this->call('vendor:publish', ['--provider' => 'SensioLabs\SecurityChecker\SecurityCheckerServiceProvider']);
$result = Artisan::call('security-checker:check');
if (strpos($result, 'WARNING') !== false) {
$this->error('Security vulnerabilities detected!');
}
}
composer.json:
"scripts": {
"post-update-cmd": [
"@security-checker"
]
}
--directory flag to scan specific paths (e.g., ./packages/*).False Positives:
symfony/http-foundation:4.0 but you use 5.4).composer.lock or Symfony’s tracker.Archived Package:
Performance:
vendor/bin/security-checker security:check --cache=./security-cache
JSON Parsing:
if (!isset($data['advisories'])) {
throw new \RuntimeException('Unexpected output format');
}
--verbose to debug API issues or missing advisories.vendor/bin/security-checker security:check --retries=3
vendor/bin/security-checker security:check --cache=./cache --offline
Custom Advisories:
Laravel Notifications:
Notifiable trait to email teams on vulnerabilities:
use SensioLabs\SecurityChecker\SecurityChecker;
$checker = new SecurityChecker();
$advisories = $checker->check();
if ($advisories->hasVulnerable()) {
User::first()->notify(new SecurityAlert($advisories));
}
GitHub Actions:
actions/github-script to comment PRs with vulnerability links:
const { data } = await github.rest.securityCodeScanning.listFindingsForRepo();
// Post as PR comment
SECURITY_CHECKER_API_KEY for private repos).composer.lock, not composer.json, for accurate results.How can I help you explore Laravel packages today?