1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yoghi\Bundle\MaddaBundle\Command; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
use SensioLabs\Security\SecurityChecker; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
11
|
|
|
|
12
|
|
|
class CheckSecurityCommand extends Command |
13
|
|
|
{ |
14
|
|
|
private $logger; |
15
|
|
|
// private $errors; |
16
|
|
|
|
17
|
|
|
public function __construct(LoggerInterface $logger = null) |
18
|
|
|
{ |
19
|
|
|
$this->logger = $logger; |
20
|
|
|
parent::__construct(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('security:check') |
27
|
|
|
->setDescription('security check') |
28
|
|
|
// ->addArgument('srcfile', InputArgument::REQUIRED, 'File xml sorgente') |
|
|
|
|
29
|
|
|
// ->addArgument('tipologia', InputArgument::REQUIRED, 'Tipologia delle sessioni') |
|
|
|
|
30
|
|
|
// ->addOption('clean', null, InputOption::VALUE_OPTIONAL, 'Option clean output directory') |
|
|
|
|
31
|
|
|
; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
|
|
$io = new SymfonyStyle($input, $output); |
|
|
|
|
37
|
|
|
$io->title('Secuirty Check'); |
38
|
|
|
|
39
|
|
|
$fileName = __DIR__.'composer.lock'; |
40
|
|
|
|
41
|
|
|
if ($this->logger) { |
42
|
|
|
$this->logger->info('Start security check on '.$fileName); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
//@see: https://github.com/sensiolabs/security-checker |
46
|
|
|
$checker = new SecurityChecker(); |
47
|
|
|
$alerts = $checker->check('composer.lock'); |
48
|
|
|
|
49
|
|
|
count($alerts) > 0 ? $io->error($alerts) : $io->success('security checked!'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.