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/Definition/ClosureDefinition.php (5 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
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Definition;
7
8
use PHPSA\CompiledExpression;
9
use PHPSA\Compiler\SymbolTable;
10
use PHPSA\Context;
11
use PhpParser\Node;
12
use PHPSA\Compiler\Parameter;
13
use PHPSA\Compiler\Types;
14
use PHPSA\Variable;
15
16
/**
17
 * Closure Definition
18
 *
19
 * @package PHPSA\Definition
20
 */
21
class ClosureDefinition extends ParentDefinition
22
{
23
    /**
24
     * @todo Use Finder
25
     *
26
     * @var string
27
     */
28
    protected $filepath;
29
30
    /**
31
     * @var Node\Expr\Closure
32
     */
33
    protected $statement;
34
35
    /**
36
     * @var int
37
     */
38
    protected $returnTypes = CompiledExpression::MIXED;
39
40
    /**
41
     * @var array
42
     */
43
    protected $possibleReturnTypes = [];
44
45
    /**
46
     * @var SymbolTable
47
     */
48
    protected $symbolTable;
49
50
    /**
51
     * @param Node\Expr\Closure $statement
52
     */
53
    public function __construct(Node\Expr\Closure $statement)
54
    {
55
        $this->symbolTable = new SymbolTable();
56
        $this->statement = $statement;
57
    }
58
59
    /**
60
     * @param Context $context
61
     */
62
    public function preCompile(Context $context)
63
    {
64
        if ($this->statement->uses) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->statement->uses of type PhpParser\Node\Expr\ClosureUse[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
65
            /**
66
             * Store variables from User to next restore Context
67
             */
68
            foreach ($this->statement->uses as $variable) {
69
                $variable = $context->getSymbol($variable->var);
0 ignored issues
show
Are you sure the assignment to $variable is correct as $context->getSymbol($variable->var) (which targets PHPSA\Context::getSymbol()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
                if ($variable) {
71
                    $variable->incGets();
72
73
                    $this->symbolTable->add(clone $variable);
74
                }
75
            }
76
        }
77
    }
78
79
    /**
80
     * Compile function to check it
81
     *
82
     * @param Context $context
83
     * @return bool
84
     */
85
    public function compile(Context $context)
0 ignored issues
show
This operation has 576 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
86
    {
87
        if ($this->compiled) {
88
            return true;
89
        }
90
91
        $context->setFilepath($this->filepath);
92
        $this->compiled = true;
93
94
        $context->clearSymbols();
95
96
        // @todo rewrite when we will use symbol table in all places!
97
        foreach ($this->symbolTable->getVariables() as $variable) {
98
            $context->addVariable($variable);
99
        }
100
101
        if ($context->scopePointer) {
102
            if ($context->scopePointer->isClassMethod()) {
103
                /** @var \PHPSA\Definition\ClassMethod $method */
104
                $method = $context->scopePointer->getObject();
105
106
                if (!$method->isStatic()) {
107
                    $thisPtr = new Variable('this', $this, CompiledExpression::OBJECT);
108
                    $thisPtr->incGets();
109
110
                    $this->symbolTable->add($thisPtr);
111
                    $context->addVariable($thisPtr);
112
                }
113
            } elseif ($context->scopePointer->isClosure()) {
114
                /** @var \PHPSA\Definition\ClosureDefinition $closure */
115
                $closure = $context->scopePointer->getObject();
116
117
                $thisPtr = $closure->getSymbolTable()->get('this');
118
                if ($thisPtr) {
119
                    $thisPtr->incGets();
120
                    $context->addVariable($thisPtr);
121
                }
122
            }
123
        }
124
125
        $context->scopePointer = $this->getPointer();
126
        $context->setScope(null);
127
128
        if (count($this->statement->stmts) == 0) {
129
            return $context->notice(
130
                'not-implemented-function',
131
                sprintf('Closure %s() is not implemented', $this->name),
132
                $this->statement
133
            );
134
        }
135
136
        if (count($this->statement->params) > 0) {
137
            /** @var  Node\Param $parameter */
138
            foreach ($this->statement->params as $parameter) {
139
                $type = CompiledExpression::UNKNOWN;
140
141
                if ($parameter->type) {
142
                    if (is_string($parameter->type)) {
143
                        $type = Types::getType($parameter->type);
144
                    } elseif ($parameter->type instanceof Node\Name) {
145
                        $type = CompiledExpression::OBJECT;
146
                    }
147
                }
148
149
                $context->addVariable(
150
                    new Parameter($parameter->name, null, $type, $parameter->byRef)
151
                );
152
            }
153
        }
154
155
        foreach ($this->statement->stmts as $st) {
156
            \PHPSA\nodeVisitorFactory($st, $context);
157
        }
158
159
        return true;
160
    }
161
162
    /**
163
     * @param CompiledExpression[] $arguments
164
     * @param Context $context
165
     * @return CompiledExpression
166
     */
167
    public function run(array $arguments, Context $context)
0 ignored issues
show
The parameter $arguments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
    {
169
        return new CompiledExpression();
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public function getFilepath()
176
    {
177
        return $this->filepath;
178
    }
179
180
    /**
181
     * @param string $filepath
182
     */
183
    public function setFilepath($filepath)
184
    {
185
        $this->filepath = $filepath;
186
    }
187
188
    /**
189
     * @return string
190
     */
191
    public function getNamespace()
192
    {
193
        return $this->namespace;
194
    }
195
196
    /**
197
     * @return SymbolTable
198
     */
199
    public function getSymbolTable()
200
    {
201
        return $this->symbolTable;
202
    }
203
}
204