Issues (9)

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/ReflectionFile.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
 * Parser Reflection API
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\ParserReflection;
12
13
14
use Go\ParserReflection\Instrument\PathResolver;
15
use PhpParser\Node;
16
use PhpParser\Node\Stmt\Namespace_;
17
18
/**
19
 * AST-based reflector for the source file
20
 */
21
class ReflectionFile
22
{
23
24
    /**
25
     * Name of the file for reflectino
26
     *
27
     * @var string
28
     */
29
    protected $fileName;
30
31
    /**
32
     * List of namespaces in the file
33
     *
34
     * @var ReflectionFileNamespace[]|array
35
     */
36
    protected $fileNamespaces;
37
38
    /**
39
     * Top-level nodes for the file
40
     *
41
     * @var Node[]
42
     */
43
    private $topLevelNodes;
44
45
    /**
46
     * ReflectionFile constructor.
47
     *
48
     * @param string $fileName Name of the file to reflect
49
     * @param null|array|Node[] $topLevelNodes Optional corresponding list of AST nodes for that file
50
     */
51 3051
    public function __construct($fileName, $topLevelNodes = null)
52
    {
53 3051
        if (!is_string($fileName)) {
54 2
            throw new \InvalidArgumentException(
55 2
                sprintf(
56 2
                    '$fileName must be a string, but a %s was passed',
57 2
                    gettype($fileName)
58
                )
59
            );
60
        }
61 3051
        $fileName            = PathResolver::realpath($fileName);
62 3051
        $this->fileName      = $fileName;
0 ignored issues
show
Documentation Bug introduced by Lisachenko Alexander
It seems like $fileName can also be of type array or boolean. However, the property $fileName is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
63 3051
        $this->topLevelNodes = $topLevelNodes ?: ReflectionEngine::parseFile($fileName);
64 3051
    }
65
66
    /**
67
     * Returns a namespace from the file or false if no such a namespace
68
     *
69
     * @param string $namespaceName
70
     *
71
     * @return bool|ReflectionFileNamespace
72
     */
73 3031
    public function getFileNamespace($namespaceName)
74
    {
75 3031
        if ($this->hasFileNamespace($namespaceName)) {
76 3031
            return $this->fileNamespaces[$namespaceName];
77
        }
78
79 1
        return false;
80
    }
81
82
    /**
83
     * Gets the list of namespaces in the file
84
     *
85
     * @return array|ReflectionFileNamespace[]
86
     */
87 3041
    public function getFileNamespaces()
88
    {
89 3041
        if (!isset($this->fileNamespaces)) {
90 3041
            $this->fileNamespaces = $this->findFileNamespaces();
91
        }
92
93 3041
        return $this->fileNamespaces;
94
    }
95
96
    /**
97
     * Returns the name of current reflected file
98
     *
99
     * @return string
100
     */
101 1
    public function getName()
102
    {
103 1
        return $this->fileName;
104
    }
105
106
    /**
107
     * Returns an AST-nodes for file
108
     *
109
     * @return Node[]
110
     */
111
    public function getNodes()
112
    {
113
        return $this->topLevelNodes;
114
    }
115
116
    /**
117
     * Returns the presence of namespace in the file
118
     *
119
     * @param string $namespaceName Namespace to check
120
     *
121
     * @return bool
122
     */
123 3032
    public function hasFileNamespace($namespaceName)
124
    {
125 3032
        $namespaces = $this->getFileNamespaces();
126
127 3032
        return isset($namespaces[$namespaceName]);
128
    }
129
130
    /**
131
     * Checks if the current file is in strict mode
132
     *
133
     * @return bool
134
     */
135 4
    public function isStrictMode()
136
    {
137
        // declare statement for the strict_types can be only top-level node
138 4
        $topLevelNode = reset($this->topLevelNodes);
139 4
        if (!$topLevelNode instanceof Node\Stmt\Declare_) {
140 1
            return false;
141
        }
142
143 3
        $declareStatement = reset($topLevelNode->declares);
144 3
        $isStrictTypeKey  = $declareStatement->key->toString() === 'strict_types';
145 3
        $isScalarValue    = $declareStatement->value instanceof Node\Scalar\LNumber;
146 3
        $isStrictMode     = $isStrictTypeKey && $isScalarValue && $declareStatement->value->value === 1;
147
148 3
        return $isStrictMode;
149
    }
150
151
    /**
152
     * Searches for file namespaces in the given AST
153
     *
154
     * @return array|ReflectionFileNamespace[]
155
     */
156 3041
    private function findFileNamespaces()
157
    {
158 3041
        $namespaces = array();
159
160
        // namespaces can be only top-level nodes, so we can scan them directly
161 3041
        foreach ($this->topLevelNodes as $topLevelNode) {
162 3041
            if ($topLevelNode instanceof Namespace_) {
163 3041
                $namespaceName = $topLevelNode->name ? $topLevelNode->name->toString() : '';
164
165 3041
                $namespaces[$namespaceName] = new ReflectionFileNamespace(
166 3041
                    $this->fileName,
167
                    $namespaceName,
168
                    $topLevelNode
169
                );
170
            }
171
        }
172
173 3041
        return $namespaces;
174
    }
175
}
176