forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityChecker.php
More file actions
93 lines (78 loc) · 2.38 KB
/
Copy pathSecurityChecker.php
File metadata and controls
93 lines (78 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace PHPCensor\Plugin;
use PHPCensor;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
use PHPCensor\Model\BuildError;
use PHPCensor\ZeroConfigPluginInterface;
use SensioLabs\Security\SecurityChecker as BaseSecurityChecker;
/**
* SensioLabs Security Checker Plugin
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class SecurityChecker extends Plugin implements ZeroConfigPluginInterface
{
/**
* @var int
*/
protected $allowedWarnings;
/**
* @return string
*/
public static function pluginName()
{
return 'security_checker';
}
/**
* {@inheritdoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->allowedWarnings = 0;
if (isset($options['zero_config']) && $options['zero_config']) {
$this->allowedWarnings = -1;
}
if (array_key_exists('allowed_warnings', $options)) {
$this->allowedWarnings = (int)$options['allowed_warnings'];
}
}
/**
* {@inheritdoc}
*/
public static function canExecuteOnStage($stage, Build $build)
{
$path = $build->getBuildPath() . 'composer.lock';
if (file_exists($path) && $stage === Build::STAGE_TEST) {
return true;
}
return false;
}
public function execute()
{
$success = true;
$checker = new BaseSecurityChecker();
$result = $checker->check($this->builder->buildPath . 'composer.lock');
$warnings = json_decode((string)$result, true);
if ($warnings) {
foreach ($warnings as $library => $warning) {
foreach ($warning['advisories'] as $data) {
$this->build->reportError(
$this->builder,
self::pluginName(),
$library . ' (' . $warning['version'] . ")\n" . $data['cve'] . ': ' . $data['title'] . "\n" . $data['link'],
BuildError::SEVERITY_CRITICAL,
'-',
'-'
);
}
}
if ($this->allowedWarnings != -1 && ($result->count() > $this->allowedWarnings)) {
$success = false;
}
}
return $success;
}
}