Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/configuration/ConfigurationBuilder.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file is part of cloak.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace cloak\configuration;
13
14
use cloak\AnalyzerConfiguration;
15
use cloak\value\CoverageBounds;
16
use cloak\analyzer\Analyzer;
17
use cloak\analyzer\AnalyzeDriver;
18
use cloak\analyzer\AdapterResolver;
19
use cloak\reporter\Reporter;
20
21
22
/**
23
 * Class ConfigurationBuilder
24
 * @package cloak\configuration
25
 */
26
class ConfigurationBuilder
27
{
28
29
    /**
30
     * @var \cloak\analyzer\AnalyzeDriver
31
     */
32
    private $driver;
33
34
    /**
35
     * @var \cloak\reporter\Reporter
36
     */
37
    private $reporter;
38
39
    /**
40
     * @var string[]
41
     */
42
    private $includeFiles;
43
44
    /**
45
     * @var string[]
46
     */
47
    private $excludeFiles;
48
49
    /**
50
     * @var \cloak\value\CoverageBounds
51
     */
52
    private $coverageBounds;
53
54
    /**
55
     * @var string
56
     */
57
    private $reportDirectory;
58
59
60
    public function __construct()
61
    {
62
        $this->includeFiles = [];
63
        $this->excludeFiles = [];
64
    }
65
66
    /**
67
     * @param AnalyzeDriver $driver
68
     * @return $this
69
     */
70
    public function driver(AnalyzeDriver $driver)
71
    {
72
        $this->driver = $driver;
73
        return $this;
74
    }
75
76
    /**
77
     * @param Reporter $reporter
78
     * @return $this
79
     */
80
    public function reporter(Reporter $reporter)
81
    {
82
        $this->reporter = $reporter;
83
        return $this;
84
    }
85
86
    /**
87
     * @param string $pattern
88
     * @return $this
89
     */
90
    public function includeFile($pattern)
91
    {
92
        $this->includeFiles[] = $pattern;
93
        return $this;
94
    }
95
96
    /**
97
     * @param string $pattern
98
     * @return $this
99
     */
100
    public function excludeFile($pattern)
101
    {
102
        $this->excludeFiles[] = $pattern;
103
        return $this;
104
    }
105
106
    /**
107
     * @param string[] $patterns
108
     * @return $this
109
     */
110
    public function includeFiles(array $patterns)
111
    {
112
        foreach ($patterns as $pattern) {
113
            $this->includeFile($pattern);
114
        }
115
        return $this;
116
    }
117
118
    /**
119
     * @param string[] $patterns
120
     * @return $this
121
     */
122
    public function excludeFiles(array $patterns)
123
    {
124
        foreach ($patterns as $pattern) {
125
            $this->excludeFile($pattern);
126
        }
127
        return $this;
128
    }
129
130
    /**
131
     * @param string $directoryPath
132
     * @return $this
133
     */
134
    public function reportDirectory($directoryPath)
135
    {
136
        $this->reportDirectory = $directoryPath;
137
        return $this;
138
    }
139
140
    /**
141
     * @param float $critical
142
     * @param float $satisfactory
143
     * @return $this
144
     */
145
    public function coverageBounds($critical, $satisfactory)
146
    {
147
        $this->coverageBounds = new CoverageBounds($critical, $satisfactory);
148
        return $this;
149
    }
150
151
    protected function detectDriver()
152
    {
153
        if ($this->driver instanceof AnalyzeDriver) {
154
            return;
155
        }
156
157
        $resolver = new AdapterResolver([
158
            '\cloak\analyzer\adapter\XdebugAdapter',
159
            '\cloak\analyzer\adapter\HHVMAdapter'
160
        ]);
161
        $adapter = $resolver->resolve();
162
163
        $this->driver = new Analyzer($adapter);
0 ignored issues
show
It seems like $adapter defined by $resolver->resolve() on line 161 can be null; however, cloak\analyzer\Analyzer::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
164
    }
165
166
    /**
167
     * @return AnalyzeDriver
168
     */
169
    public function getDriver()
170
    {
171
        return $this->driver;
172
    }
173
174
    /**
175
     * @return Reporter
176
     */
177
    public function getReporter()
178
    {
179
        return $this->reporter;
180
    }
181
182
    /**
183
     * @return string[]
184
     */
185
    public function getIncludeFiles()
186
    {
187
        return $this->includeFiles;
188
    }
189
190
    /**
191
     * @return string[]
192
     */
193
    public function getExcludeFiles()
194
    {
195
        return $this->excludeFiles;
196
    }
197
198
    /**
199
     * @return CoverageBounds
200
     */
201
    public function getCoverageBounds()
202
    {
203
        return $this->coverageBounds;
204
    }
205
206
    /**
207
     * @return string
208
     */
209
    public function getReportDirectory()
210
    {
211
        return $this->reportDirectory;
212
    }
213
214
    /**
215
     * @return AnalyzerConfiguration
216
     */
217
    public function build()
218
    {
219
        $this->detectDriver();
220
221
        $values = [
222
            'driver' => $this->driver,
223
            'reporter' => $this->reporter,
224
            'includeFiles' => $this->includeFiles,
225
            'excludeFiles' => $this->excludeFiles,
226
            'coverageBounds' => $this->coverageBounds,
227
            'reportDirectory' => $this->reportDirectory
228
        ];
229
230
        return new AnalyzerConfiguration($values);
231
    }
232
233
}
234