Issues (387)

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.

Compiler/Pass/NamespaceTreeBuilder.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
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Compiler\Pass;
17
18
use InvalidArgumentException;
19
use phpDocumentor\Compiler\CompilerPassInterface;
20
use phpDocumentor\Descriptor\Collection;
21
use phpDocumentor\Descriptor\DescriptorAbstract;
22
use phpDocumentor\Descriptor\NamespaceDescriptor;
23
use phpDocumentor\Descriptor\ProjectDescriptor;
24
use phpDocumentor\Reflection\Fqsen;
25
26
/**
27
 * Rebuilds the namespace tree from the elements found in files.
28
 *
29
 * On every compiler pass is the namespace tree rebuild to aid in the process
30
 * of incremental updates. The Files Collection in the Project Descriptor is the
31
 * only location where aliases to elements may be serialized.
32
 *
33
 * If the namespace tree were to be persisted then both locations needed to be
34
 * invalidated if a file were to change.
35
 */
36
class NamespaceTreeBuilder implements CompilerPassInterface
37
{
38
    const COMPILER_PRIORITY = 9000;
39
40 1
    public function getDescription(): string
41
    {
42 1
        return 'Build "namespaces" index and add namespaces to "elements"';
43
    }
44
45 6
    public function execute(ProjectDescriptor $project): void
46
    {
47 6
        $project->getIndexes()->get('elements', new Collection())->set('~\\', $project->getNamespace());
48 6
        $project->getIndexes()->get('namespaces', new Collection())->set('\\', $project->getNamespace());
49
50 6
        foreach ($project->getFiles() as $file) {
51 6
            $this->addElementsOfTypeToNamespace($project, $file->getConstants()->getAll(), 'constants');
52 6
            $this->addElementsOfTypeToNamespace($project, $file->getFunctions()->getAll(), 'functions');
53 6
            $this->addElementsOfTypeToNamespace($project, $file->getClasses()->getAll(), 'classes');
54 6
            $this->addElementsOfTypeToNamespace($project, $file->getInterfaces()->getAll(), 'interfaces');
55 6
            $this->addElementsOfTypeToNamespace($project, $file->getTraits()->getAll(), 'traits');
56
        }
57
58
        /** @var NamespaceDescriptor $namespace */
59 6
        foreach ($project->getIndexes()->get('namespaces')->getAll() as $namespace) {
60 6
            if ($namespace->getNamespace() !== '') {
61 6
                $this->addToParentNamespace($project, $namespace);
62
            }
63
        }
64 6
    }
65
66
    /**
67
     * Adds the given elements of a specific type to their respective Namespace Descriptors.
68
     *
69
     * This method will assign the given elements to the namespace as registered in the namespace field of that
70
     * element. If a namespace does not exist yet it will automatically be created.
71
     *
72
     * @param DescriptorAbstract[] $elements Series of elements to add to their respective namespace.
73
     * @param string $type Declares which field of the namespace will be populated with the given series of elements.
74
     *                     This name will be transformed to a getter which must exist. Out of performance
75
     *                     considerations will no effort be done to verify whether the provided type is valid.
76
     */
77 6
    protected function addElementsOfTypeToNamespace(ProjectDescriptor $project, array $elements, string $type): void
78
    {
79
        /** @var DescriptorAbstract $element */
80 6
        foreach ($elements as $element) {
81 6
            $namespaceName = (string) $element->getNamespace();
82
            //TODO: find out why this can happen. Some bug in the assembler?
83 6
            if ($namespaceName === '') {
84
                $namespaceName = '\\';
85
            }
86
87 6
            $namespace = $project->getIndexes()->get('namespaces', new Collection())->get($namespaceName);
88
89 6
            if ($namespace === null) {
90 6
                $namespace = new NamespaceDescriptor();
91 6
                $fqsen = new Fqsen($namespaceName);
92 6
                $namespace->setName($fqsen->getName());
93 6
                $namespace->setFullyQualifiedStructuralElementName($fqsen);
94 6
                $namespaceName = substr((string) $fqsen, 0, -strlen($fqsen->getName()) - 1);
95 6
                $namespace->setNamespace($namespaceName);
96 6
                $project->getIndexes()
97 6
                    ->get('namespaces')
98 6
                    ->set((string) $namespace->getFullyQualifiedStructuralElementName(), $namespace);
99 6
                $this->addToParentNamespace($project, $namespace);
100
            }
101
102
            // replace textual representation with an object representation
103 6
            $element->setNamespace($namespace);
104
105
            // add element to namespace
106 6
            $getter = 'get' . ucfirst($type);
107
108
            /** @var Collection $collection */
109 6
            $collection = $namespace->{$getter}();
110 6
            $collection->add($element);
111
        }
112 6
    }
113
114 6
    private function addToParentNamespace(ProjectDescriptor $project, NamespaceDescriptor $namespace): void
115
    {
116
        /** @var NamespaceDescriptor $parent */
117 6
        $parent = $project->getIndexes()->get('namespaces')->get($namespace->getNamespace());
118 6
        $project->getIndexes()->get('elements')->set(
119 6
            '~' . (string) $namespace->getFullyQualifiedStructuralElementName(),
120 6
            $namespace
121
        );
122
123
        try {
124 6
            if ($parent === null) {
125 6
                $parent = new NamespaceDescriptor();
126 6
                $fqsen = new Fqsen($namespace->getNamespace());
0 ignored issues
show
It seems like $namespace->getNamespace() targeting phpDocumentor\Descriptor...bstract::getNamespace() can also be of type object<phpDocumentor\Des...or\NamespaceDescriptor>; however, phpDocumentor\Reflection\Fqsen::__construct() does only seem to accept string, 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...
127 6
                $parent->setFullyQualifiedStructuralElementName($fqsen);
128 6
                $parent->setName($fqsen->getName());
129 6
                $namespaceName = substr((string) $fqsen, 0, -strlen($parent->getName()) - 1);
130 6
                $parent->setNamespace($namespaceName === '' ? '\\' : $namespaceName);
131 6
                $project->getIndexes()
132 6
                    ->get('namespaces')
133 6
                    ->set((string) $parent->getFullyQualifiedStructuralElementName(), $parent);
134 6
                $this->addToParentNamespace($project, $parent);
135
            }
136
137 6
            $namespace->setParent($parent);
138 6
            $parent->getChildren()->set($namespace->getName(), $namespace);
139
        } catch (InvalidArgumentException $e) {
140
            //bit hacky but it works for now.
141
            //$project->getNamespace()->getChildren()->add($namespace);
142
        }
143 6
    }
144
}
145