Issues (132)

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/Compiler.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
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
use PHPSA\Definition\ClassDefinition;
9
use PHPSA\Definition\FunctionDefinition;
10
use PHPSA\Definition\RuntimeClassDefinition;
11
use PHPSA\Definition\TraitDefinition;
12
use ReflectionClass;
13
14
/**
15
 * Compiler component
16
 */
17
class Compiler
18
{
19
    /**
20
     * @var ClassDefinition[]
21
     */
22
    protected $classes = [];
23
24
    /**
25
     * @var TraitDefinition[]
26
     */
27
    protected $traits = [];
28
29
    /**
30
     * @var FunctionDefinition[]
31
     */
32
    protected $functions = [];
33
34
    /**
35
     * @param ClassDefinition $class
36
     */
37
    public function addClass(ClassDefinition $class)
38
    {
39
        $this->classes[implode('\\', [$class->getNamespace(), $class->getName()])] = $class;
40
    }
41
42
    /**
43
     * @param TraitDefinition $class
44
     */
45
    public function addTrait(TraitDefinition $class)
46
    {
47
        $this->traits[implode('\\', [$class->getNamespace(), $class->getName()])] = $class;
48
    }
49
50
    /**
51
     * @param FunctionDefinition $function
52
     */
53
    public function addFunction(FunctionDefinition $function)
54
    {
55
        $this->functions[] = $function;
56
    }
57
58
    /**
59
     * @param Context $context
60
     */
61 1
    public function compile(Context $context)
62
    {
63 1
        $context->scopePointer = null;
64
65
        /**
66
         * @todo Implement class map...
67
         */
68 1
        foreach ($this->classes as $class) {
69
            $extends = $class->getExtendsClass();
70
            if ($extends) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $extends of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
71
                if (isset($this->classes[$extends])) {
72
                    $class->setExtendsClassDefinition($this->classes[$extends]);
73
                } else {
74
                    if (class_exists($extends, true)) {
75
                        $class->setExtendsClassDefinition(
76
                            new RuntimeClassDefinition(
77
                                new ReflectionClass(
78
                                    $extends
79
                                )
80
                            )
81
                        );
82
                    }
83
                }
84
            }
85
        }
86
87 1
        foreach ($this->functions as $function) {
88
            /**
89
             * @todo Configuration
90
             *
91
             * Ignore functions compiling from vendor
92
             */
93
            $checkVendor = strpos($function->getFilepath(), './vendor');
94
            if ($checkVendor !== false && $checkVendor < 3) {
95
                continue;
96
            }
97
98
            $function->compile($context);
99
        }
100
101 1
        foreach ($this->traits as $trait) {
102
            /**
103
             * @todo Configuration
104
             *
105
             * Ignore traits compiling from vendor
106
             */
107
            $checkVendor = strpos($trait->getFilepath(), './vendor');
108
            if ($checkVendor !== false && $checkVendor < 3) {
109
                continue;
110
            }
111
112
            $trait->compile($context);
113
        }
114
115 1
        foreach ($this->classes as $class) {
116
            /**
117
             * @todo Configuration
118
             *
119
             * Ignore Classes compiling from vendor
120
             */
121
            $checkVendor = strpos($class->getFilepath(), './vendor');
122
            if ($checkVendor !== false && $checkVendor < 3) {
123
                continue;
124
            }
125
126
            $class->compile($context);
127
        }
128 1
    }
129
130
    /**
131
     * Try to find function with $namespace from pre-compiled function(s)
132
     *
133
     * @param string $name
134
     * @param string|null $namespace
135
     * @return bool|FunctionDefinition
136
     */
137
    public function getFunctionNS($name, $namespace = null)
138
    {
139
        foreach ($this->functions as $function) {
140
            if ($function->getName() == $name && $function->getNamespace() == $namespace) {
141
                return $function;
142
            }
143
        }
144
145
        return false;
146
    }
147
148
    /**
149
     * @param string $name
150
     * @return ClassDefinition|null
151
     */
152
    public function getClass($name)
153
    {
154
        if (isset($this->classes[$name])) {
155
            return $this->classes[$name];
156
        }
157
158
        return null;
159
    }
160
161
    /**
162
     * @param string $name
163
     * @return TraitDefinition|null
164
     */
165
    public function getTrait($name)
166
    {
167
        if (isset($this->traits[$name])) {
168
            return $this->traits[$name];
169
        }
170
171
        return null;
172
    }
173
174
    /**
175
     * Try to find function from pre-compiled function(s)
176
     *
177
     * @param string $name
178
     * @return bool|FunctionDefinition
179
     */
180
    public function getFunction($name)
181
    {
182
        foreach ($this->functions as $function) {
183
            if ($function->getName() == $name) {
184
                return $function;
185
            }
186
        }
187
188
        return false;
189
    }
190
191
    /**
192
     * @return FunctionDefinition[]
193
     */
194
    public function getFunctions()
195
    {
196
        return $this->functions;
197
    }
198
199
    /**
200
     * @return ClassDefinition[]
201
     */
202
    public function getClasses()
203
    {
204
        return $this->classes;
205
    }
206
}
207