Issues (32)

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/Config/Configuration.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
namespace Storeman\Config;
4
5
use Symfony\Component\Validator\Mapping\ClassMetadata;
6
use Zend\Stdlib\ArraySerializableInterface;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
class Configuration implements ArraySerializableInterface
10
{
11
    /**
12
     * The local base path of the archive.
13
     *
14
     * @var string
15
     */
16
    protected $path = './';
17
18
    /**
19
     * Set of excluded paths.
20
     *
21
     * @var string[]
22
     */
23
    protected $exclude = [];
24
25
    /**
26
     * Identity to be visible in synchronization log.
27
     *
28
     * @var string
29
     */
30
    protected $identity = 'unknown';
31
32
    /**
33
     * Identifier of the index builder to use.
34
     *
35
     * @var string
36
     */
37
    protected $indexBuilder = 'standard';
38
39
    /**
40
     * List of file checksums to be used for integrity checks and modification detection.
41
     *
42
     * @var string[]
43
     */
44
    protected $fileChecksums = ['sha2-256', 'sha1', 'md5'];
45
46
    /**
47
     * Array of vault configurations.
48
     *
49
     * @var VaultConfiguration[]
50
     */
51
    protected $vaults = [];
52
53
    /**
54
     * @return string
55
     */
56
    public function getPath(): string
57
    {
58
        return $this->path;
59
    }
60
61
    /**
62
     * @param string $path
63
     *
64
     * @return Configuration
65
     */
66
    public function setPath(string $path): Configuration
67
    {
68
        if (substr($path, -1) !== '/')
69
        {
70
            $path .= '/';
71
        }
72
73
        $this->path = $path;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @return \string[]
80
     */
81
    public function getExclude(): array
82
    {
83
        return $this->exclude;
84
    }
85
86
    /**
87
     * @param \string[] $paths
88
     *
89
     * @return Configuration
90
     */
91
    public function setExclude(array $paths): Configuration
92
    {
93
        $this->exclude = array_values($paths);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_values($paths) of type array<integer,object<string>> is incompatible with the declared type array<integer,string> of property $exclude.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param string $path
100
     *
101
     * @return Configuration
102
     */
103
    public function addExclusion(string $path): Configuration
104
    {
105
        $this->exclude[] = $path;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getIdentity(): string
114
    {
115
        return $this->identity;
116
    }
117
118
    /**
119
     * @param string $identity
120
     *
121
     * @return Configuration
122
     */
123
    public function setIdentity(string $identity): Configuration
124
    {
125
        $this->identity = $identity;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getIndexBuilder(): string
134
    {
135
        return $this->indexBuilder;
136
    }
137
138
    /**
139
     * @param string $indexBuilder
140
     * @return $this
141
     */
142
    public function setIndexBuilder(string $indexBuilder): Configuration
143
    {
144
        $this->indexBuilder = $indexBuilder;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @return string[]
151
     */
152
    public function getFileChecksums(): array
153
    {
154
        return $this->fileChecksums;
155
    }
156
157
    /**
158
     * @param string[] $fileChecksums
159
     * @return Configuration
160
     */
161
    public function setFileChecksums(array $fileChecksums): Configuration
162
    {
163
        $this->fileChecksums = array_values($fileChecksums);
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return VaultConfiguration[]
170
     */
171
    public function getVaults(): array
172
    {
173
        return $this->vaults;
174
    }
175
176
    /**
177
     * @param string $title
178
     *
179
     * @return VaultConfiguration
180
     */
181
    public function getVaultByTitle(string $title): VaultConfiguration
182
    {
183
        if ($vaultConfiguration = $this->getVaultConfigurationByTitle($title))
184
        {
185
            return $vaultConfiguration;
186
        }
187
188
        throw new \InvalidArgumentException("Unknown vault configuration requested: {$title}");
189
    }
190
191
    public function addVault(VaultConfiguration $configuration): Configuration
192
    {
193
        if (array_search($configuration, $this->vaults) === false)
194
        {
195
            $this->vaults[] = $configuration;
196
        }
197
198
        return $this;
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204
    public function exchangeArray(array $array)
205
    {
206
        if ($diff = array_diff(array_keys($array), array_keys(get_object_vars($this))))
207
        {
208
            throw new \InvalidArgumentException("Invalid index(es): " . implode(',', $diff));
209
        }
210
211
        foreach ($array as $key => $value)
212
        {
213
            if ($key === 'vaults')
214
            {
215
                if (!is_array($value))
216
                {
217
                    throw new \InvalidArgumentException();
218
                }
219
220
                $this->vaults = [];
221
222
                foreach ($value as $val)
223
                {
224
                    if (!is_array($val))
225
                    {
226
                        throw new \InvalidArgumentException();
227
                    }
228
229
                    $vaultConfig = new VaultConfiguration($this);
230
                    $vaultConfig->exchangeArray($val);
231
                }
232
            }
233
            else
234
            {
235
                // using setter to prevent skipping validation
236
                call_user_func([$this, 'set' . ucfirst($key)], $value);
237
            }
238
        }
239
    }
240
241
    /**
242
     * {@inheritdoc}
243
     */
244
    public function getArrayCopy()
245
    {
246
        $return = get_object_vars($this);
247
        $return['vaults'] = array_values(array_map(function(VaultConfiguration $vaultConfiguration) {
248
249
            return $vaultConfiguration->getArrayCopy();
250
251
        }, $this->vaults));
252
253
        return $return;
254
    }
255
256
    protected function getVaultConfigurationByTitle(string $title): ?VaultConfiguration
257
    {
258
        foreach ($this->vaults as $vaultConfiguration)
259
        {
260
            if ($vaultConfiguration->getTitle() === $title)
261
            {
262
                return $vaultConfiguration;
263
            }
264
        }
265
266
        return null;
267
    }
268
269
    public static function loadValidatorMetadata(ClassMetadata $metadata)
270
    {
271
        $metadata->addPropertyConstraint('path', new Assert\NotBlank());
272
        $metadata->addPropertyConstraint('identity', new Assert\NotBlank());
273
        $metadata->addPropertyConstraint('vaults', new Assert\Count(['min' => 1]));
274
    }
275
}
276