Issues (55)

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/Parser/ParsingContext.php (1 issue)

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 Benoth\StaticReflection\Parser;
4
5
use Benoth\StaticReflection\Reflection\Reflection;
6
use Benoth\StaticReflection\Reflection\ReflectionFunctionAbstract;
7
use Benoth\StaticReflection\ReflectionsIndex;
8
use PhpParser\Error as PhpParserException;
9
use PhpParser\NodeTraverserInterface;
10
use PhpParser\Parser as ParserInterface;
11
12
class ParsingContext
13
{
14
    protected $parser;
15
    protected $traverser;
16
    protected $index;
17
18
    protected $file;
19
    protected $errors = [];
20
21
    protected $namespace;
22
    protected $aliases = [];
23
    protected $reflection;
24
    protected $functionLike;
25
26 1128
    public function __construct(ParserInterface $parser, NodeTraverserInterface $traverser, ReflectionsIndex $index)
27
    {
28 1128
        ini_set('xdebug.max_nesting_level', 10000);
29
30 1128
        $this->parser    = $parser;
31 1128
        $this->traverser = $traverser;
32 1128
        $this->index     = $index;
33 1128
    }
34
35 1128
    public function parseFile($file)
36
    {
37 1128
        $this->file        = $file;
38 1128
        $this->errors      = [];
39
40
        try {
41 1128
            $this->traverser->traverse($this->parser->parse($this->getFileContent()));
0 ignored issues
show
It seems like $this->parser->parse($this->getFileContent()) targeting PhpParser\Parser::parse() can also be of type null; however, PhpParser\NodeTraverserInterface::traverse() does only seem to accept array<integer,object<PhpParser\Node>>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42 1128
        } catch (PhpParserException $e) {
43 27
            $this->addError($this->getFilePath(), 0, $e->getMessage());
44
        }
45
46 1128
        $this->file = null;
47
48 1128
        return $this;
49
    }
50
51 1128
    public function getFilePath()
52
    {
53 1128
        return $this->file;
54
    }
55
56 1128
    public function getFileContent()
57
    {
58 1128
        if (!file_exists($this->getFilePath())) {
59 27
            throw new PhpParserException('File '.$this->getFilePath().' does not exist');
60
        }
61
62 1101
        return file_get_contents($this->getFilePath());
63
    }
64
65
    /**
66
     * @param string $name
67
     */
68 258
    public function addAlias($alias, $name)
69
    {
70 258
        $this->aliases[$alias] = $name;
71 258
    }
72
73 1101
    public function getAliases()
74
    {
75 1101
        return $this->aliases;
76
    }
77
78
    /**
79
     * @param string $namespace
80
     */
81 1047
    public function enterNamespace($namespace)
82
    {
83 1047
        $this->namespace = $namespace;
84 1047
        $this->aliases   = array();
85
86 1047
        return $this;
87
    }
88
89 1047
    public function leaveNamespace()
90
    {
91 1047
        $this->namespace = null;
92 1047
        $this->aliases   = array();
93
94 1047
        return $this;
95
    }
96
97 6
    public function getNamespace()
98
    {
99 6
        return $this->namespace;
100
    }
101
102 1101
    public function enterReflection(Reflection $reflection)
103
    {
104 1101
        $this->reflection = $reflection;
105 1101
    }
106
107 1104
    public function leaveReflection()
108
    {
109 1104
        if ($this->reflection === null) {
110 6
            return;
111
        }
112
113 1101
        $this->index->addReflection($this->reflection);
114
115 1101
        $this->reflection = null;
116 1101
    }
117
118 1101
    public function enterFunctionLike(ReflectionFunctionAbstract $reflection)
119
    {
120 1101
        $this->functionLike = $reflection;
121 1101
    }
122
123 1104
    public function getFunctionLike()
124
    {
125 1104
        return $this->functionLike;
126
    }
127
128 1104
    public function leaveFunctionLike()
129
    {
130 1104
        $this->functionLike = null;
131 1104
    }
132
133 1104
    public function getReflection()
134
    {
135 1104
        return $this->reflection;
136
    }
137
138 6
    public function addErrors($name, $line, array $errors)
139
    {
140 6
        foreach ($errors as $error) {
141 6
            $this->addError($name, $line, $error);
142 6
        }
143 6
    }
144
145 33
    public function addError($name, $line, $error)
146
    {
147 33
        $this->errors[] = sprintf('%s on "%s" in %s:%d', $error, $name, $this->file, $line);
148 33
    }
149
150 18
    public function getErrors()
151
    {
152 18
        return $this->errors;
153
    }
154
}
155