Issues (47)

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.

lib/Metadata/BaseMetadataFactory.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 Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Component\DocumentManager\Metadata;
13
14
use PHPCR\NodeInterface;
15
use Sulu\Component\DocumentManager\ClassNameInflector;
16
use Sulu\Component\DocumentManager\Event\MetadataLoadEvent;
17
use Sulu\Component\DocumentManager\Events;
18
use Sulu\Component\DocumentManager\Exception\MetadataNotFoundException;
19
use Sulu\Component\DocumentManager\Metadata;
20
use Sulu\Component\DocumentManager\MetadataFactoryInterface;
21
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
22
23
/**
24
 * Simple metadata factory which uses an array map.
25
 *
26
 * Note that this class does not  implement the getMetadataForPhpcrNode method
27
 * as that would require a circular dependency.
28
 */
29
class BaseMetadataFactory implements MetadataFactoryInterface
30
{
31
    /**
32
     * @var array
33
     */
34
    private $aliasMap = [];
35
36
    /**
37
     * @var array
38
     */
39
    private $classMap = [];
40
41
    /**
42
     * @var array
43
     */
44
    private $phpcrTypeMap = [];
45
46
    /**
47
     * @var EventDispatcherInterface
48
     */
49
    private $dispatcher;
50
51
    /**
52
     * @var Metadata[]
53
     */
54
    private $metadata = [];
55
56
    /**
57
     * @param array $mapping
58
     */
59
    public function __construct(EventDispatcherInterface $dispatcher, array $mapping)
60
    {
61
        $this->dispatcher = $dispatcher;
62
63
        foreach ($mapping as $map) {
64
            $this->aliasMap[$map['alias']] = $map;
65
            $this->classMap[$map['class']] = $map;
66
            $this->phpcrTypeMap[$map['phpcr_type']] = $map;
67
        }
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 View Code Duplication
    public function getMetadataForAlias($alias)
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...
74
    {
75
        if (!isset($this->aliasMap[$alias])) {
76
            throw new MetadataNotFoundException(sprintf(
77
                'Metadata with alias "%s" not found, known aliases: "%s"',
78
                $alias, implode('", "', array_keys($this->aliasMap))
79
            ));
80
        }
81
82
        $map = $this->aliasMap[$alias];
83
84
        return $this->loadMetadata($map);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 View Code Duplication
    public function getMetadataForPhpcrType($phpcrType)
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...
91
    {
92
        if (!isset($this->phpcrTypeMap[$phpcrType])) {
93
            throw new MetadataNotFoundException(sprintf(
94
                'Metadata with phpcrType "%s" not found, known phpcrTypes: "%s"',
95
                $phpcrType, implode('", "', array_keys($this->phpcrTypeMap))
96
            ));
97
        }
98
99
        $map = $this->phpcrTypeMap[$phpcrType];
100
101
        return $this->loadMetadata($map);
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function hasMetadataForPhpcrType($phpcrType)
108
    {
109
        return isset($this->phpcrTypeMap[$phpcrType]);
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function hasMetadataForClass($class)
116
    {
117
        $class = ClassNameInflector::getUserClassName($class);
118
119
        return isset($this->classMap[$class]);
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 View Code Duplication
    public function getMetadataForClass($class)
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...
126
    {
127
        $class = ClassNameInflector::getUserClassName($class);
128
129
        if (!isset($this->classMap[$class])) {
130
            throw new MetadataNotFoundException(sprintf(
131
                'Metadata with class "%s" not found, known classes: "%s"',
132
                $class, implode('", "', array_keys($this->classMap))
133
            ));
134
        }
135
136
        $map = $this->classMap[$class];
137
138
        return $this->loadMetadata($map);
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function hasAlias($alias)
145
    {
146
        return isset($this->aliasMap[$alias]);
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function getAliases()
153
    {
154
        return array_keys($this->aliasMap);
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function getMetadataForPhpcrNode(NodeInterface $node)
161
    {
162
        throw new \BadMethodCallException(
163
            'The BaseMetadataFactory does not implement this method'
164
        );
165
    }
166
167
    /**
168
     * @return array
169
     */
170
    public function getPhpcrTypeMap()
171
    {
172
        return $this->phpcrTypeMap;
173
    }
174
175
    /**
176
     * @param array $mapping
177
     *
178
     * @return Metadata
179
     */
180
    private function loadMetadata($mapping)
181
    {
182
        $mapping = array_merge([
183
            'alias' => null,
184
            'phpcr_type' => null,
185
            'class' => null,
186
            'mapping' => [],
187
        ], $mapping);
188
189
        if (isset($this->metadata[$mapping['alias']])) {
190
            return $this->metadata[$mapping['alias']];
191
        }
192
193
        $metadata = new Metadata();
194
        $metadata->setAlias($mapping['alias']);
195
        $metadata->setPhpcrType($mapping['phpcr_type']);
196
        $metadata->setClass($mapping['class']);
197
198
        foreach ($mapping['mapping'] as $fieldName => $fieldMapping) {
199
            $fieldMapping = array_merge([
200
                'encoding' => 'content',
201
                'property' => $fieldName,
202
            ], $fieldMapping);
203
            $metadata->addFieldMapping($fieldName, $fieldMapping);
204
        }
205
206
        $event = new MetadataLoadEvent($metadata);
207
        $this->dispatcher->dispatch(Events::METADATA_LOAD, $event);
208
209
        $this->metadata[$mapping['alias']] = $metadata;
210
211
        return $metadata;
212
    }
213
}
214