Issues (138)

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.

Composer/Factory/MakeLocatorForComposerJson.php (6 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
declare(strict_types=1);
4
5
namespace Roave\BetterReflection\SourceLocator\Type\Composer\Factory;
6
7
use Roave\BetterReflection\SourceLocator\Ast\Locator;
8
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
9
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\FailedToParseJson;
10
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\InvalidProjectDirectory;
11
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\MissingComposerJson;
12
use Roave\BetterReflection\SourceLocator\Type\Composer\Psr\Psr0Mapping;
13
use Roave\BetterReflection\SourceLocator\Type\Composer\Psr\Psr4Mapping;
14
use Roave\BetterReflection\SourceLocator\Type\Composer\PsrAutoloaderLocator;
15
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
16
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
17
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;
18
use function array_filter;
19
use function array_map;
20
use function array_merge;
21
use function file_exists;
22
use function file_get_contents;
23
use function is_array;
24
use function is_dir;
25
use function json_decode;
26
use function realpath;
27
28
final class MakeLocatorForComposerJson
29
{
30 6
    public function __invoke(string $installationPath, Locator $astLocator) : SourceLocator
31
    {
32 6
        $realInstallationPath = (string) realpath($installationPath);
33
34 6
        if (! is_dir($realInstallationPath)) {
35 1
            throw InvalidProjectDirectory::atPath($installationPath);
36
        }
37
38 5
        $composerJsonPath = $realInstallationPath . '/composer.json';
39
40 5
        if (! file_exists($composerJsonPath)) {
41 1
            throw MissingComposerJson::inProjectPath($installationPath);
42
        }
43
44
        /** @var array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}}|null $composer */
45 4
        $composer = json_decode((string) file_get_contents($composerJsonPath), true);
46
47 4
        if (! is_array($composer)) {
48 1
            throw FailedToParseJson::inFile($composerJsonPath);
49
        }
50
51 3
        $pathPrefix          = $realInstallationPath . '/';
52 3
        $classMapPaths       = $this->prefixPaths($this->packageToClassMapPaths($composer), $pathPrefix);
53 3
        $classMapFiles       = array_filter($classMapPaths, 'is_file');
54 3
        $classMapDirectories = array_filter($classMapPaths, 'is_dir');
55 3
        $filePaths           = $this->prefixPaths($this->packageToFilePaths($composer), $pathPrefix);
56
57 3
        return new AggregateSourceLocator(array_merge(
58
            [
59 3
                new PsrAutoloaderLocator(
60 3
                    Psr4Mapping::fromArrayMappings(
61 3
                        $this->prefixWithInstallationPath($this->packageToPsr4AutoloadNamespaces($composer), $pathPrefix)
62
                    ),
63
                    $astLocator
64
                ),
65 3
                new PsrAutoloaderLocator(
66 3
                    Psr0Mapping::fromArrayMappings(
67 3
                        $this->prefixWithInstallationPath($this->packageToPsr0AutoloadNamespaces($composer), $pathPrefix)
68
                    ),
69
                    $astLocator
70
                ),
71 3
                new DirectoriesSourceLocator($classMapDirectories, $astLocator),
72
            ],
73
            ...array_map(static function (string $file) use ($astLocator) : array {
74 2
                return [new SingleFileSourceLocator($file, $astLocator)];
75 3
            }, array_merge($classMapFiles, $filePaths))
76
        ));
77
    }
78
79
    /**
80
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
81
     *
82
     * @return array<string, array<int, string>>
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
83
     */
84 3
    private function packageToPsr4AutoloadNamespaces(array $package) : array
85
    {
86
        return array_map(static function ($namespacePaths) : array {
87 3
            return (array) $namespacePaths;
88 3
        }, $package['autoload']['psr-4'] ?? []);
89
    }
90
91
    /**
92
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
93
     *
94
     * @return array<string, array<int, string>>
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
95
     */
96 3
    private function packageToPsr0AutoloadNamespaces(array $package) : array
97
    {
98
        return array_map(static function ($namespacePaths) : array {
99 3
            return (array) $namespacePaths;
100 3
        }, $package['autoload']['psr-0'] ?? []);
101
    }
102
103
    /**
104
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
105
     *
106
     * @return array<int, string>
0 ignored issues
show
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
107
     */
108 3
    private function packageToClassMapPaths(array $package) : array
109
    {
110 3
        return $package['autoload']['classmap'] ?? [];
111
    }
112
113
    /**
114
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
115
     *
116
     * @return array<int, string>
0 ignored issues
show
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
117
     */
118 3
    private function packageToFilePaths(array $package) : array
119
    {
120 3
        return $package['autoload']['files'] ?? [];
121
    }
122
123
    /**
124
     * @param array<string, array<int, string>> $paths
125
     *
126
     * @return array<string, array<int, string>>
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
127
     */
128 3
    private function prefixWithInstallationPath(array $paths, string $trimmedInstallationPath) : array
129
    {
130
        return array_map(function (array $paths) use ($trimmedInstallationPath) : array {
131 3
            return $this->prefixPaths($paths, $trimmedInstallationPath);
132 3
        }, $paths);
133
    }
134
135
    /**
136
     * @param array<int, string> $paths
137
     *
138
     * @return array<int, string>
0 ignored issues
show
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
139
     */
140 3
    private function prefixPaths(array $paths, string $prefix) : array
141
    {
142
        return array_map(static function (string $path) use ($prefix) {
143 3
            return $prefix . $path;
144 3
        }, $paths);
145
    }
146
}
147