Issues (1490)

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/Tools/Plugin/Phing.php (3 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
3
namespace Fabrica\Tools\Plugin;
4
5
use Fabrica\Tools\Builder;
6
use Fabrica\Models\Infra\Ci\Build;
7
use Fabrica\Tools\Plugin;
8
9
/**
10
 * Phing Plugin - Provides access to Phing functionality.
11
 *
12
 * @author Pavel Pavlov <[email protected]>
13
 */
14
class Phing extends Plugin
15
{
16
    protected $buildFile  = 'build.xml';
17
    protected $targets    = ['build'];
18
    protected $properties = [];
19
    protected $propertyFile;
20
21
    /**
22
     * @return string
23
     */
24
    public static function pluginName()
25
    {
26
        return 'phing';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function __construct(Builder $builder, Build $build, array $options = [])
33
    {
34
        parent::__construct($builder, $build, $options);
35
36
        /*
37
         * Sen name of a non default build file
38
         */
39
        if (isset($options['build_file'])) {
40
            $this->setBuildFile($options['build_file']);
41
        }
42
43
        if (isset($options['targets'])) {
44
            $this->setTargets($options['targets']);
45
        }
46
47
        if (isset($options['properties'])) {
48
            $this->setProperties($options['properties']);
49
        }
50
51
        if (isset($options['property_file'])) {
52
            $this->setPropertyFile($options['property_file']);
53
        }
54
55
        $this->executable = $this->findBinary('phing');
56
    }
57
58
    /**
59
     * Executes Phing and runs a specified targets
60
     */
61
    public function execute()
62
    {
63
        $phingExecutable = $this->executable;
64
65
        $cmd[] = $phingExecutable . ' -f ' . $this->getBuildFilePath();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$cmd was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cmd = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
66
67
        if ($this->getPropertyFile()) {
68
            $cmd[] = '-propertyfile ' . $this->getPropertyFile();
69
        }
70
71
        $cmd[] = $this->propertiesToString();
72
73
        $cmd[] = '-logger phing.listener.DefaultLogger';
74
        $cmd[] = $this->targetsToString();
75
        $cmd[] = '2>&1';
76
77
        return $this->builder->executeCommand(implode(' ', $cmd), $this->directory, $this->targets);
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getTargets()
84
    {
85
        return $this->targets;
86
    }
87
88
    /**
89
     * Converts an array of targets into a string.
90
     *
91
     * @return string
92
     */
93
    private function targetsToString()
94
    {
95
        return implode(' ', $this->targets);
96
    }
97
98
    /**
99
     * @param array|string $targets
100
     *
101
     * @return $this
102
     */
103
    public function setTargets($targets)
104
    {
105
        if (is_string($targets)) {
106
            $targets = [$targets];
107
        }
108
109
        $this->targets = $targets;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getBuildFile()
116
    {
117
        return $this->buildFile;
118
    }
119
120
    /**
121
     * @param mixed $buildFile
122
     *
123
     * @return $this
124
     * @throws \Exception
125
     */
126
    public function setBuildFile($buildFile)
127
    {
128
        if (!file_exists($this->directory . $buildFile)) {
129
            throw new \Exception('Specified build file does not exist.');
130
        }
131
132
        $this->buildFile = $buildFile;
133
    }
134
135
    /**
136
     * Get phing build file path.
137
     *
138
     * @return string
139
     */
140
    public function getBuildFilePath()
141
    {
142
        return $this->directory . $this->buildFile;
143
    }
144
145
    /**
146
     * @return mixed
147
     */
148
    public function getProperties()
149
    {
150
        return $this->properties;
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function propertiesToString()
157
    {
158
        /**
159
         * fix the problem when execute phing out of the build dir
160
         *
161
         * @ticket 748
162
         */
163
        if (!isset($this->properties['project.basedir'])) {
164
            $this->properties['project.basedir'] = $this->getDirectory();
0 ignored issues
show
The method getDirectory() does not seem to exist on object<Fabrica\Tools\Plugin\Phing>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
165
        }
166
167
        $propertiesString = [];
168
169
        foreach ($this->properties as $name => $value) {
170
            $propertiesString[] = '-D' . $name . '="' . $value . '"';
171
        }
172
173
        return implode(' ', $propertiesString);
174
    }
175
176
    /**
177
     * @param array|string $properties
178
     *
179
     * @return $this
180
     */
181
    public function setProperties($properties)
182
    {
183
        if (is_string($properties)) {
184
            $properties = [$properties];
185
        }
186
187
        $this->properties = $properties;
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getPropertyFile()
194
    {
195
        return $this->propertyFile;
196
    }
197
198
    /**
199
     * @param string $propertyFile
200
     *
201
     * @return $this
202
     * @throws \Exception
203
     */
204
    public function setPropertyFile($propertyFile)
205
    {
206
        if (!file_exists($this->getDirectory() . '/' . $propertyFile)) {
0 ignored issues
show
The method getDirectory() does not seem to exist on object<Fabrica\Tools\Plugin\Phing>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
207
            throw new \Exception('Specified property file does not exist.');
208
        }
209
210
        $this->propertyFile = $propertyFile;
211
    }
212
}
213