Last active
February 6, 2016 12:08
-
-
Save ClaudioVarandas/dd2ff890c3c32fd5dfd0 to your computer and use it in GitHub Desktop.
CheckSecurity Command for Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use SensioLabs\Security\SecurityChecker; | |
class CheckSecurity extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'security:checker'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'SensioLabs Security Checker'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$checker = new SecurityChecker(); | |
$alerts = $checker->check(base_path() . '/composer.lock'); | |
if (!empty($alerts)) | |
{ | |
foreach ($alerts as $package => $alert) | |
{ | |
$this->error('Security advisories found!'); | |
$this->info('======================'); | |
$this->info('Package: ' . $package); | |
foreach ($alert['advisories'] as $advisory) | |
{ | |
$this->info('Version: ' . $alert['version']); | |
$this->info('Title: ' . $advisory['title']); | |
$this->info('Link: ' . $advisory['link']); | |
if($advisory['cve'] != "") | |
{ | |
$this->info('CVE: ' . $advisory['cve']); | |
} | |
} | |
} | |
} | |
else | |
{ | |
$this->info('No security advisories found!'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment