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.

Metadata/AnnotationReader.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\Metadata;
4
5
use Happyr\SerializerBundle\Annotation\SerializerAnnotation;
6
use Happyr\SerializerBundle\PropertyManager\AttributeExtractor;
7
use Symfony\Component\Finder\Finder;
8
use Doctrine\Common\Annotations\Reader;
9
use Symfony\Component\Finder\SplFileInfo;
10
11
/**
12
 * Read annotations.
13
 *
14
 * @author Tobias Nyholm <[email protected]>
15
 */
16
class AnnotationReader implements MetadataReader
17
{
18
    /**
19
     * @var array
20
     */
21
    private $paths;
22
23
    /**
24
     * @var Reader
25
     */
26
    private $reader;
27
28
    /**
29
     * @var AttributeExtractor
30
     */
31
    private $attributeExtractor;
32
33
    /**
34
     * @param array              $paths
35
     * @param Reader             $reader
36
     * @param AttributeExtractor $attributeExtractor
37
     */
38 23
    public function __construct(array $paths, Reader $reader, AttributeExtractor $attributeExtractor)
39
    {
40 23
        $this->paths = $paths;
41 23
        $this->reader = $reader;
42 23
        $this->attributeExtractor = $attributeExtractor;
43 23
    }
44
45
    /**
46
     * @return Metadata[]
47
     */
48
    public function getMetadata()
49
    {
50
        // Create a function to filter out our annotations
51 23
        $filterAnnotations = function ($annotation) {
52 23
            return $annotation instanceof SerializerAnnotation;
53 23
        };
54
55 23
        $metadatas = [];
56 23
        foreach ($this->paths as $path) {
57 23
            $finder = new Finder();
58 23
            $finder->in($path)->notName('*Test.php')->name('*.php');
59
            /** @var SplFileInfo $file */
60 23
            foreach ($finder as $file) {
61 23
                if (null === $fqcn = $this->getFullyQualifiedClassName($file->getPathname())) {
62
                    continue;
63
                }
64 23
                $metadata = new Metadata($fqcn);
65
66 23
                $attributes = $this->attributeExtractor->getAttributes($fqcn);
67 23
                $reflectionClass = new \ReflectionClass($fqcn);
68 23
                $classAnnotations = array_filter($this->reader->getClassAnnotations($reflectionClass), $filterAnnotations);
69
70 23
                $propertyAnnotations = [];
71 23
                foreach ($attributes['property'] as $propertyName => $bool) {
0 ignored issues
show
The expression $attributes['property'] of type string is not traversable.
Loading history...
72 23
                    $propertyAnnotations[$propertyName] = array_filter($this->reader->getPropertyAnnotations($reflectionClass->getProperty($propertyName)), $filterAnnotations);
73 23
                }
74
75 23
                $methodAnnotations = [];
76 23
                foreach ($attributes['method'] as $methodName => $bool) {
0 ignored issues
show
The expression $attributes['method'] of type string is not traversable.
Loading history...
77 23
                    $methodAnnotations[$methodName] = array_filter($this->reader->getMethodAnnotations($reflectionClass->getMethod($methodName)), $filterAnnotations);
78 23
                }
79
80 23
                if ($this->buildMetadataFromAnnotation($metadata, $classAnnotations, $methodAnnotations, $propertyAnnotations)) {
81 23
                    $metadatas[] = $metadata;
82 23
                }
83 23
            }
84 23
        }
85
86 23
        return $metadatas;
87
    }
88
89
    /**
90
     * Build a metadata object from annotations.
91
     *
92
     * @param Metadata $metadata
93
     * @param $classAnnotations
94
     * @param $methodAnnotations
95
     * @param $propertyAnnotations
96
     */
97 23
    private function buildMetadataFromAnnotation(Metadata $metadata, $classAnnotations, $methodAnnotations, $propertyAnnotations)
98
    {
99 23
        $return = false;
100
        $a = [
101 23
            'setPropertyMetadata' => $propertyAnnotations,
102 23
            'setMethodMetadata' => $methodAnnotations,
103 23
        ];
104
105 23
        foreach ($a as $function => $typeAnnotations) {
106 23
            foreach ($typeAnnotations as $name => $annotations) {
107 23
                $data = [];
108
                /** @var SerializerAnnotation $annotation */
109 23
                foreach ($annotations as $annotation) {
110 23
                    $data[$annotation->getName()] = $annotation->getValue();
111 23
                }
112
113 23
                $metadata->$function($name, $data);
114 23
                if (count($data) > 0) {
115 23
                    $return = true;
116 23
                }
117 23
            }
118 23
        }
119
120
        // Class annotations
121
        /* @var SerializerAnnotation $annotation */
122 23
        $data = [];
123 23
        foreach ($classAnnotations as $annotation) {
124 23
            $data[$annotation->getName()] = $annotation->getValue();
125 23
        }
126 23
        $metadata->setClassMetadata($data);
127 23
        if (count($data) > 0) {
128 23
            $return = true;
129 23
        }
130
131 23
        return $return;
132
    }
133
134
    /**
135
     * @param string $path
136
     *
137
     * @return null|string
138
     */
139 23
    private function getFullyQualifiedClassName($path)
140
    {
141 23
        $src = file_get_contents($path);
142 23
        $filename = basename($path);
143 23
        $classname = substr($filename, 0, -4);
144
145 23
        if (preg_match('|^namespace\s+(.+?);$|sm', $src, $matches)) {
146 23
            return $matches[1].'\\'.$classname;
147
        }
148
149
        return;
150
    }
151
}
152