Issues (218)

Security Analysis    not enabled

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/Logic/Analyser.php (5 issues)

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
namespace Finder\Logic;
3
4
use Finder\Logic\Output\AbstractOutput;
5
use Finder\Logic\Output\Filter\OutputFilterInterface;
6
use Finder\Logic\Output\TriggerableInterface;
7
8
/**
9
 * Run all script analysers and outputs their result.
10
 *
11
 * @package qa
12
 */
13
class Analyser
14
{
15
    const EVENT_STARTING_ANALYSIS = 0;
16
    const EVENT_STARTING_TOOL = 1;
17
    const EVENT_FINISHED_TOOL = 2;
18
    const EVENT_FINISHED_ANALYSIS = 3;
19
20
    const VERSION = '0.7.1';
21
22
    protected $defaultLanguage = 'Php';
23
24
    /**
25
     * Composer binaries path.
26
     *
27
     * @var string directory path.
28
     */
29
    protected $binariesPath;
30
31
    /**
32
     * Analysis target.
33
     *
34
     * @var string[] file or directory path.
35
     */
36
    protected $analysedPaths;
37
38
    /**
39
     * Ignored paths.
40
     *
41
     * @var string[] comma separated list of directories to ignore.
42
     */
43
    protected $ignoredPaths;
44
45
    /**
46
     * Output service.
47
     *
48
     * @var AbstractOutput output instance.
49
     */
50
    protected $output;
51
52
    /**
53
     * Analysis result filter.
54
     *
55
     * @var OutputFilterInterface filter instance.
56
     */
57
    protected $resultsFilter;
58
59
    /**
60
     * Set dependencies and initialize CLI.
61
     *
62
     * @param AbstractOutput $output        Output target.
63
     * @param string         $binariesPath  Composer binaries path.
64
     * @param string[]       $analysedPaths target file or directory path.
65
     * @param string[]       $ignoredPaths  comma separated list of ignored directories.
66
     */
67 View Code Duplication
    public function __construct(AbstractOutput $output, $binariesPath, $analysedPaths, $ignoredPaths, $project = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $this->output = $output;
70
        $this->binariesPath = $binariesPath;
71
        $this->analysedPaths = $analysedPaths;
72
        $this->ignoredPaths = $ignoredPaths;
73
74
        if (!$project) {
75
            $this->languageClass = 'Finder\\Logic\\Language\\'.$this->defaultLanguage;
0 ignored issues
show
The property languageClass does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
76
        }
77
    }
78
79
    /**
80
     * Run each configured PHP analysis tool.
81
     *
82
     * @return boolean true if it didn't find code issues.
83
     */
84
    public function run()
85
    {
86
        $result = $this->createResult();
87
        $this->trigger(
88
            self::EVENT_STARTING_ANALYSIS,
89
            ['ignoredPaths' => $this->ignoredPaths]
0 ignored issues
show
array('ignoredPaths' => $this->ignoredPaths) is of type array<string,array<integ...rray<integer,string>"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
        );
91
92 View Code Duplication
        foreach ($this->getAnalysisTools() as $tool) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
            $message = ['description' => $tool->getDescription()];
94
            $this->trigger(self::EVENT_STARTING_TOOL, $message);
0 ignored issues
show
$message is of type array<string,?,{"description":"?"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
            $tool->run($this->getAnalysedPaths());
96
            $result->mergeWith($tool->getAnalysisResult());
97
            $this->trigger(self::EVENT_FINISHED_TOOL);
98
        }
99
100
        if ($this->resultsFilter) {
101
            $result->setResultsFilter($this->resultsFilter);
102
        }
103
104
        $this->output->result($result);
105
        $this->trigger(self::EVENT_FINISHED_ANALYSIS);
106
107
        return !$result->hasIssues();
108
    }
109
110
    /**
111
     * Call an output trigger if supported.
112
     *
113
     * @param  int         $event   occurred event.
114
     * @param  string|null $message optional message.
115
     * @return void
116
     */
117
    protected function trigger($event, $message = null)
118
    {
119
        if ($this->output instanceof TriggerableInterface) {
120
            $this->output->trigger($event, $message);
121
        }
122
    }
123
124
    /**
125
     * Get a list of paths to be ignored by the analysis.
126
     *
127
     * @return string[] a list of file and/or directory paths.
128
     */
129
    public function getIgnoredPaths()
130
    {
131
        return $this->ignoredPaths;
132
    }
133
134
    /**
135
     * Analysis target path.
136
     *
137
     * @return string[] target path.
138
     */
139
    public function getAnalysedPaths()
140
    {
141
        return $this->analysedPaths;
142
    }
143
144
    /**
145
     * Add an output filter to delegate to the analysis result object.
146
     *
147
     * @param OutputFilterInterface $filter filter instance.
148
     */
149
    public function setResultsFilter(OutputFilterInterface $filter)
150
    {
151
        $this->resultsFilter = $filter;
152
    }
153
154
    /**
155
     * Set target files and/or directories to be analysed.
156
     *
157
     * @param  string[] $paths target paths.
158
     * @return void
159
     */
160
    public function setAnalysedPaths(array $paths)
161
    {
162
        $this->analysedPaths = $paths;
163
    }
164
165
    /**
166
     * List of PHP analys integration classes.
167
     *
168
     * @return string[] array of class names.
169
     */
170
    protected function getAnalysisToolsClasses()
171
    {
172
        return $this->languageClass::getAnalysisToolsClasses();
173
    }
174
175
    /**
176
     * Set of PHP analys integration objects.
177
     *
178
     * @return Finder\Logic\Tools\AbstractIntegrationTool[] set of objects.
179
     */
180
    protected function getAnalysisTools()
181
    {
182
        $objects = [];
183
        $tools = $this->getAnalysisToolsClasses();
184
185
        if (empty($tools)) {
186
            return $objects;
187
        }
188
189
        foreach ($tools as $className) {
190
            $tool = new $className($this->binariesPath, sys_get_temp_dir());
191
            $tool->setIgnoredPaths($this->getIgnoredPaths());
192
            $objects[] = $tool;
193
        }
194
195
        return $objects;
196
    }
197
198
    /**
199
     * Create an empty analysis result.
200
     *
201
     * @return AnalysisResult instance.
202
     */
203
    protected function createResult()
204
    {
205
        return new AnalysisResult;
206
    }
207
}
208