Issues (5)

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.

Normalizer/MetadataAwareNormalizer.php (2 issues)

Labels
Severity

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 Happyr\SerializerBundle\Normalizer;
4
5
use Happyr\SerializerBundle\Annotation\ExclusionPolicy;
6
use Happyr\SerializerBundle\Metadata\Metadata;
7
use Happyr\SerializerBundle\PropertyManager\AttributeExtractor;
8
use Happyr\SerializerBundle\PropertyManager\ReflectionPropertyAccess;
9
use Happyr\SerializerBundle\PropertyManager\PropertyNameConverter;
10
use Symfony\Component\Serializer\Exception\LogicException;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
class MetadataAwareNormalizer extends SerializerAwareNormalizer implements NormalizerInterface
18
{
19
    use GroupValidationTrait;
20
21
    /**
22
     * @var array
23
     */
24
    private $metadata;
25
26
    /**
27
     * @var AttributeExtractor
28
     */
29
    private $attributeExtractor;
30
31
    /**
32
     * @var PropertyNameConverter
33
     */
34
    private $propertyNameConverter;
35
36
    /**
37
     * @param array                 $metadata
38
     * @param AttributeExtractor    $attributeExtractor
39
     * @param PropertyNameConverter $pnc
40
     */
41 23
    public function __construct(array $metadata, AttributeExtractor $attributeExtractor, PropertyNameConverter $pnc)
42
    {
43 23
        $this->metadata = $metadata;
44 23
        $this->attributeExtractor = $attributeExtractor;
45 23
        $this->propertyNameConverter = $pnc;
46 23
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 11
    public function normalize($object, $format = null, array $context = [])
52
    {
53 11
        $meta = $this->getMetadata($object);
54 11
        $attributes = $this->attributeExtractor->getAttributes($object);
55
56 11
        $normalizedData = [];
57 11
        foreach ($attributes['property'] as $propertyName => $bool) {
0 ignored issues
show
The expression $attributes['property'] of type string is not traversable.
Loading history...
58 11
            $this->normalizeProperty($normalizedData, $meta, $object, $propertyName, $context);
59 11
        }
60 11
        foreach ($attributes['method'] as $propertyName => $bool) {
0 ignored issues
show
The expression $attributes['method'] of type string is not traversable.
Loading history...
61 2
            $this->normalizeMethod($normalizedData, $meta, $object, $propertyName, $context);
62 11
        }
63
64 11
        foreach ($normalizedData as $name => $value) {
65 11
            if (null !== $value && !is_scalar($value)) {
66 1
                if (!$this->serializer instanceof NormalizerInterface) {
67
                    throw new LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $name));
68
                }
69
70 1
                $normalizedData[$name] = $this->serializer->normalize($value, $format, $context);
71 1
            }
72 11
        }
73
74 11
        return $normalizedData;
75
    }
76
77
    /**
78
     * Normalize a property.
79
     *
80
     * @param array $normalizedData
81
     * @param array $meta
82
     * @param $object
83
     * @param $propertyName
84
     * @param array $context
85
     */
86 11
    protected function normalizeProperty(array &$normalizedData, array $meta, $object, $propertyName, array $context)
87
    {
88 11
        if (!isset($meta['property'][$propertyName])) {
89
            $meta['property'][$propertyName] = [];
90
        }
91
92
        // Default exclusion policy is NONE
93 11
        $exclusionPolicy = isset($meta['class']['exclusion_policy']) ? $meta['class']['exclusion_policy'] : ExclusionPolicy::NONE;
94
95
        // If this property should be in the output
96 11
        $included = $exclusionPolicy === ExclusionPolicy::NONE;
97
98 11
        $groups = ['Default'];
99 11
        $value = ReflectionPropertyAccess::get($object, $propertyName);
100 11
        foreach ($meta['property'][$propertyName] as $name => $metaValue) {
101
            switch ($name) {
102 11
                case 'exclude':
103
                    // Skip this
104 4
                    return;
105 10
                case 'expose':
106 4
                    $included = true;
107 4
                    break;
108 6
                case 'accessor':
109 1
                    if (!empty($metaValue['getter'])) {
110 1
                        $accessor = $metaValue['getter'];
111 1
                        $value = $object->$accessor();
112 1
                    }
113 1
                    break;
114 5
                case 'groups':
115 1
                    $groups = $metaValue;
116 1
                    break;
117
            }
118 11
        }
119
120
        // Validate context groups
121 11
        if (!empty($context['groups'])) {
122 1
            $included = $this->includeBasedOnGroup($context, $groups);
123 1
        }
124
125 11
        if (!$included) {
126 3
            return;
127
        }
128
129 11
        $serializedName = $this->propertyNameConverter->getSerializedName($meta['property'][$propertyName], $propertyName);
130 11
        $normalizedData[$serializedName] = $value;
131 11
    }
132
133
    /**
134
     * Normalize a method.
135
     *
136
     * @param array $normalizedData
137
     * @param array $meta
138
     * @param $object
139
     * @param $methodName
140
     * @param array $context
141
     */
142 2
    protected function normalizeMethod(array &$normalizedData, array $meta, $object, $methodName, array $context)
143
    {
144 2
        if (!isset($meta['method'][$methodName])) {
145
            $meta['method'][$methodName] = [];
146
        }
147
148
        // Methods are never serialized by default
149 2
        $included = false;
150
151 2
        $groups = ['Default'];
152 2
        foreach ($meta['method'][$methodName] as $name => $metaValue) {
153
            switch ($name) {
154
                case 'expose':
155
                    $included = true;
156
                    break;
157
                case 'groups':
158
                    $groups = $metaValue;
159
                    break;
160
            }
161 2
        }
162
163
        // Validate context groups
164 2
        if (!empty($context['groups'])) {
165
            $included = $this->includeBasedOnGroup($context, $groups);
166
        }
167
168 2
        if (!$included) {
169 2
            return;
170
        }
171
172
        $serializedName = $this->propertyNameConverter->getSerializedName($meta['method'][$methodName], $methodName);
173
        $normalizedData[$serializedName] = $object->$methodName();
174
    }
175
176
    /**
177
     * @param mixed $data
178
     * @param null  $format
179
     *
180
     * @return bool
181
     */
182 11
    public function supportsNormalization($data, $format = null)
183
    {
184 11
        if (!is_object($data)) {
185 1
            return false;
186
        }
187
188 11
        $class = get_class($data);
189
190 11
        return isset($this->metadata[$class]);
191
    }
192
193
    /**
194
     * @param object $object
195
     *
196
     * @return array
197
     */
198 11
    private function getMetadata($object)
199
    {
200 11
        $class = get_class($object);
201
202 11
        return $this->metadata[$class];
203
    }
204
}
205