Issues (201)

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/Server/ModuleFileServerManager.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
/*
4
 * This file is part of the puli/manager package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Manager\Server;
13
14
use Exception;
15
use Puli\Manager\Api\Installer\InstallerManager;
16
use Puli\Manager\Api\Installer\NoSuchInstallerException;
17
use Puli\Manager\Api\Module\RootModuleFileManager;
18
use Puli\Manager\Api\Server\Server;
19
use Puli\Manager\Api\Server\ServerCollection;
20
use Puli\Manager\Api\Server\ServerManager;
21
use stdClass;
22
use Webmozart\Expression\Expr;
23
use Webmozart\Expression\Expression;
24
use Webmozart\Json\JsonValidator;
25
use Webmozart\Json\ValidationFailedException;
26
27
/**
28
 * A server manager that stores the servers in the module file.
29
 *
30
 * @since  1.0
31
 *
32
 * @author Bernhard Schussek <[email protected]>
33
 */
34
class ModuleFileServerManager implements ServerManager
35
{
36
    /**
37
     * The extra key that stores the server data.
38
     */
39
    const SERVERS_KEY = 'servers';
40
41
    /**
42
     * @var RootModuleFileManager
43
     */
44
    private $rootModuleFileManager;
45
46
    /**
47
     * @var InstallerManager
48
     */
49
    private $installerManager;
50
51
    /**
52
     * @var ServerCollection
53
     */
54
    private $servers;
55
56
    /**
57
     * @var array
58
     */
59
    private $serversData = array();
60
61 58
    public function __construct(RootModuleFileManager $rootModuleFileManager, InstallerManager $installerManager)
62
    {
63 58
        $this->rootModuleFileManager = $rootModuleFileManager;
64 58
        $this->installerManager = $installerManager;
65 58
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 10
    public function addServer(Server $server)
71
    {
72 10
        $this->assertServersLoaded();
73
74 10
        if (!$this->installerManager->hasInstallerDescriptor($server->getInstallerName())) {
75 2
            throw NoSuchInstallerException::forInstallerName($server->getInstallerName());
76
        }
77
78 8
        $previousServers = $this->servers->toArray();
79 8
        $previousData = $this->serversData;
80
81 8
        $this->servers->add($server);
82 8
        $this->serversData[$server->getName()] = $this->serverToData($server);
83
84
        try {
85 8
            $this->persistServersData();
86 2
        } catch (Exception $e) {
87 2
            $this->servers->replace($previousServers);
88 2
            $this->serversData = $previousData;
89
90 2
            throw $e;
91
        }
92 6
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 8
    public function removeServer($serverName)
98
    {
99 8
        $this->removeServers(Expr::method('getName', Expr::same($serverName)));
100 6
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 14
    public function removeServers(Expression $expr)
106
    {
107 14
        $this->assertServersLoaded();
108
109 14
        $previousServers = $this->servers->toArray();
110 14
        $previousData = $this->serversData;
111 14
        $save = false;
112
113 14
        foreach ($this->servers as $server) {
114 14
            if ($expr->evaluate($server)) {
115 12
                $this->servers->remove($server->getName());
116 12
                unset($this->serversData[$server->getName()]);
117 14
                $save = true;
118
            }
119
        }
120
121 14
        if (!$save) {
122 2
            return;
123
        }
124
125
        try {
126 12
            $this->persistServersData();
127 4
        } catch (Exception $e) {
128 4
            $this->servers->replace($previousServers);
129 4
            $this->serversData = $previousData;
130
131 4
            throw $e;
132
        }
133 8
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 2
    public function clearServers()
139
    {
140 2
        $this->removeServers(Expr::true());
141 2
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146 16
    public function getServer($serverName)
147
    {
148 16
        $this->assertServersLoaded();
149
150 14
        return $this->servers->get($serverName);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 27
    public function getServers()
157
    {
158 27
        $this->assertServersLoaded();
159
160 27
        return $this->servers;
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166 2
    public function findServers(Expression $expr)
167
    {
168 2
        $this->assertServersLoaded();
169
170 2
        $servers = array();
171
172 2
        foreach ($this->servers as $server) {
173 2
            if ($expr->evaluate($server)) {
174 2
                $servers[] = $server;
175
            }
176
        }
177
178 2
        return new ServerCollection($servers);
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184 18
    public function hasServer($serverName)
185
    {
186 18
        $this->assertServersLoaded();
187
188 18
        return $this->servers->contains($serverName);
189
    }
190
191
    /**
192
     * {@inheritdoc}
193
     */
194 4 View Code Duplication
    public function hasServers(Expression $expr = null)
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...
195
    {
196 4
        $this->assertServersLoaded();
197
198 4
        if (!$expr) {
199 4
            return !$this->servers->isEmpty();
200
        }
201
202 2
        foreach ($this->servers as $server) {
203 2
            if ($expr->evaluate($server)) {
204 2
                return true;
205
            }
206
        }
207
208 2
        return false;
209
    }
210
211 58
    private function assertServersLoaded()
212
    {
213 58
        if (null !== $this->servers) {
214 32
            return;
215
        }
216
217 58
        $serversData = $this->rootModuleFileManager->getExtraKey(self::SERVERS_KEY);
218
219 58
        if ($serversData) {
220 42
            $jsonValidator = new JsonValidator();
221 42
            $errors = $jsonValidator->validate($serversData, __DIR__.'/../../res/schema/servers-schema-1.0.json');
222
223 42 View Code Duplication
            if (count($errors) > 0) {
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...
224 2
                throw new ValidationFailedException(sprintf(
225 2
                    "The extra key \"%s\" is invalid:\n%s",
226 2
                    self::SERVERS_KEY,
227 2
                    implode("\n", $errors)
228
                ));
229
            }
230
        }
231
232 56
        $this->servers = new ServerCollection();
233 56
        $this->serversData = (array) $serversData;
234
235 56
        foreach ($this->serversData as $serverName => $serverData) {
236 40
            $this->servers->add($this->dataToServer($serverName, $serverData));
237
        }
238 56
    }
239
240 20
    private function persistServersData()
241
    {
242 20
        if ($this->serversData) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->serversData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
243 16
            $this->rootModuleFileManager->setExtraKey(self::SERVERS_KEY, (object) $this->serversData);
244
        } else {
245 4
            $this->rootModuleFileManager->removeExtraKey(self::SERVERS_KEY);
246
        }
247 14
    }
248
249 40
    private function dataToServer($serverName, stdClass $data)
250
    {
251 40
        return new Server(
252
            $serverName,
253 40
            $data->installer,
254 40
            $data->{'document-root'},
255 40
            isset($data->{'url-format'}) ? $data->{'url-format'} : Server::DEFAULT_URL_FORMAT,
256 40
            isset($data->parameters) ? (array) $data->parameters : array()
257
        );
258
    }
259
260 8
    private function serverToData(Server $server)
261
    {
262 8
        $data = new stdClass();
263 8
        $data->installer = $server->getInstallerName();
264 8
        $data->{'document-root'} = $server->getDocumentRoot();
265
266 8
        if (Server::DEFAULT_URL_FORMAT !== ($urlFormat = $server->getUrlFormat())) {
267 2
            $data->{'url-format'} = $urlFormat;
268
        }
269
270 8
        if ($parameters = $server->getParameterValues()) {
271 2
            $data->parameters = (object) $parameters;
272
        }
273
274 8
        return $data;
275
    }
276
}
277