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/Module/RootModuleFileConverter.php (1 issue)

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\Module;
13
14
use Puli\Manager\Api\Environment;
15
use Puli\Manager\Api\Module\InstallInfo;
16
use Puli\Manager\Api\Module\RootModuleFile;
17
use Puli\Manager\Assert\Assert;
18
use Rhumsaa\Uuid\Uuid;
19
use stdClass;
20
21
/**
22
 * Converts root module files to JSON and back.
23
 *
24
 * @since  1.0
25
 *
26
 * @author Bernhard Schussek <[email protected]>
27
 */
28
class RootModuleFileConverter extends ModuleFileConverter
29
{
30
    /**
31
     * The default order of the keys in the written module file.
32
     *
33
     * @var string[]
34
     */
35
    private static $keyOrder = array(
36
        '$schema',
37
        'name',
38
        'resources',
39
        'bindings',
40
        'binding-types',
41
        'depend',
42
        'order',
43
        'config',
44
        'plugins',
45
        'extra',
46
        'modules',
47
    );
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 6
    public function toJson($moduleFile, array $options = array())
53
    {
54 6
        Assert::isInstanceOf($moduleFile, 'Puli\Manager\Api\Module\RootModuleFile');
55
56 6
        $jsonData = new stdClass();
57 6
        $jsonData->{'$schema'} = sprintf(self::SCHEMA, self::VERSION);
58
59 6
        $this->addModuleFileToJson($moduleFile, $jsonData);
60 6
        $this->addRootModuleFileToJson($moduleFile, $jsonData);
61
62
        // Sort according to key order
63 6
        $jsonArray = (array) $jsonData;
64 6
        $orderedKeys = array_intersect_key(array_flip(self::$keyOrder), $jsonArray);
65
66 6
        return (object) array_replace($orderedKeys, $jsonArray);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 30
    public function fromJson($jsonData, array $options = array())
73
    {
74 30
        $path = isset($options['path']) ? $options['path'] : null;
75 30
        $baseConfig = isset($options['baseConfig']) ? $options['baseConfig'] : null;
76
77 30
        Assert::isInstanceOf($jsonData, 'stdClass');
78 30
        Assert::nullOrString($path, 'The "path" option should be null or a string. Got: %s');
79 30
        Assert::nullOrIsInstanceOf($baseConfig, 'Puli\Manager\Api\Config\Config', 'The "baseConfig" option should be null or an instance of %2$s. Got: %s');
80
81 30
        $moduleFile = new RootModuleFile(null, $path, $baseConfig);
82 30
        $moduleFile->setVersion($this->versioner->parseVersion($jsonData));
83
84 30
        $this->addJsonToModuleFile($jsonData, $moduleFile);
85 30
        $this->addJsonToRootModuleFile($jsonData, $moduleFile);
86
87 30
        return $moduleFile;
88
    }
89
90 6
    protected function addRootModuleFileToJson(RootModuleFile $moduleFile, stdClass $jsonData)
91
    {
92 6
        $moduleOrder = $moduleFile->getModuleOrder();
93 6
        $installInfos = $moduleFile->getInstallInfos();
94
95
        // Pass false to exclude base configuration values
96 6
        $configValues = $moduleFile->getConfig()->toRawArray(false);
97
98 6
        if (count($moduleOrder) > 0) {
99 1
            $jsonData->order = $moduleOrder;
100
        }
101
102 6
        if (count($configValues) > 0) {
103 1
            $jsonData->config = (object) $configValues;
104
        }
105
106 6
        if (array() !== $moduleFile->getPluginClasses()) {
107 2
            $jsonData->plugins = $moduleFile->getPluginClasses();
108
109 2
            sort($jsonData->plugins);
110
        }
111
112 6
        if (count($installInfos) > 0) {
113 3
            $modulesData = array();
114
115 3
            foreach ($installInfos as $installInfo) {
116 3
                $installData = new stdClass();
117 3
                $installData->{'install-path'} = $installInfo->getInstallPath();
118
119 3
                if (InstallInfo::DEFAULT_INSTALLER_NAME !== $installInfo->getInstallerName()) {
120 1
                    $installData->installer = $installInfo->getInstallerName();
121
                }
122
123 3
                if ($installInfo->hasDisabledBindingUuids()) {
124 2
                    $installData->{'disabled-bindings'} = array();
125
126 2
                    foreach ($installInfo->getDisabledBindingUuids() as $uuid) {
127 2
                        $installData->{'disabled-bindings'}[] = $uuid->toString();
128
                    }
129
130 2
                    sort($installData->{'disabled-bindings'});
131
                }
132
133 3
                if (Environment::PROD !== $installInfo->getEnvironment()) {
134 1
                    $installData->env = $installInfo->getEnvironment();
135
                }
136
137 3
                $modulesData[$installInfo->getModuleName()] = $installData;
138
            }
139
140 3
            ksort($modulesData);
141
142 3
            $jsonData->modules = (object) $modulesData;
143
        }
144 6
    }
145
146 30
    protected function addJsonToRootModuleFile(stdClass $jsonData, RootModuleFile $moduleFile)
147
    {
148 30
        if (isset($jsonData->order)) {
149 1
            $moduleFile->setModuleOrder((array) $jsonData->order);
150
        }
151
152 30
        if (isset($jsonData->plugins)) {
153 27
            $moduleFile->setPluginClasses($jsonData->plugins);
154
        }
155
156 30
        if (isset($jsonData->config)) {
157 2
            $config = $moduleFile->getConfig();
158
159 2
            foreach ($this->objectsToArrays($jsonData->config) as $key => $value) {
160 2
                $config->set($key, $value);
161
            }
162
        }
163
164 30
        if (isset($jsonData->modules)) {
165 27
            foreach ($jsonData->modules as $moduleName => $moduleData) {
166 27
                $installInfo = new InstallInfo($moduleName, $moduleData->{'install-path'});
167
168 27
                if (isset($moduleData->env)) {
169 1
                    $installInfo->setEnvironment($moduleData->env);
170
                }
171
172 27
                if (isset($moduleData->installer)) {
173 1
                    $installInfo->setInstallerName($moduleData->installer);
174
                }
175
176 27
                if (isset($moduleData->{'disabled-bindings'})) {
177 1
                    foreach ($moduleData->{'disabled-bindings'} as $uuid) {
178 1
                        $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid));
179
                    }
180
                }
181
182 27
                $moduleFile->addInstallInfo($installInfo);
183
            }
184
        }
185 30
    }
186
187 2 View Code Duplication
    private function objectsToArrays($data)
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...
188
    {
189 2
        $data = (array) $data;
190
191 2
        foreach ($data as $key => $value) {
192 2
            $data[$key] = is_object($value) ? $this->objectsToArrays($value) : $value;
193
        }
194
195 2
        return $data;
196
    }
197
}
198