Issues (387)

Branch: develop

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/phpDocumentor/Descriptor/Example/Finder.php (2 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
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\Descriptor\Example;
17
18
use phpDocumentor\Descriptor\Tag\ExampleDescriptor;
19
20
/**
21
 * Class used to find an example file's location based on a given ExampleDescriptor.
22
 */
23
class Finder
24
{
25
    /** @var string */
26
    private $sourceDirectory = '';
27
28
    /** @var string[] */
29
    private $exampleDirectories = [];
30
31
    /**
32
     * Attempts to find the example contents for the given descriptor.
33
     */
34 5
    public function find(ExampleDescriptor $descriptor): string
35
    {
36 5
        $filename = $descriptor->getFilePath();
37
38 5
        $file = $this->getExampleFileContents($filename);
39 5
        if (! $file) {
40 1
            return "** File not found : {$filename} **";
41
        }
42
43 4
        return implode('', array_slice($file, $descriptor->getStartingLine() - 1, $descriptor->getLineCount()));
44
    }
45
46
    /**
47
     * Registers the project's root directory where an 'examples' folder can be expected.
48
     */
49 1
    public function setSourceDirectory(string $directory = ''): void
50
    {
51 1
        $this->sourceDirectory = $directory;
52 1
    }
53
54
    /**
55
     * Returns the project's root directory where an 'examples' folder can be expected.
56
     */
57 1
    public function getSourceDirectory(): string
58
    {
59 1
        return $this->sourceDirectory;
60
    }
61
62
    /**
63
     * Registers a series of directories that may contain examples.
64
     *
65
     * @param string[] $directories
66
     */
67 1
    public function setExampleDirectories(array $directories = []): void
68
    {
69 1
        $this->exampleDirectories = $directories;
70 1
    }
71
72
    /**
73
     * Returns a series of directories that may contain examples.
74
     *
75
     * @return string[]
76
     */
77 1
    public function getExampleDirectories(): array
78
    {
79 1
        return $this->exampleDirectories;
80
    }
81
82
    /**
83
     * Attempts to find the requested example file and returns its contents or null if no file was found.
84
     *
85
     * This method will try several methods in search of the given example file, the first one it encounters is
86
     * returned:
87
     *
88
     * 1. Iterates through all examples folders for the given filename
89
     * 2. Checks the source folder for the given filename
90
     * 3. Checks the 'examples' folder in the current working directory for examples
91
     * 4. Checks the path relative to the current working directory for the given filename
92
     */
93 5
    private function getExampleFileContents(string $filename): ?array
94
    {
95 5
        $normalizedPath = null;
96
97 5
        foreach ($this->exampleDirectories as $directory) {
98 1
            $exampleFileFromConfig = $this->constructExamplePath($directory, $filename);
99 1
            if (is_readable($exampleFileFromConfig)) {
100 1
                $normalizedPath = $exampleFileFromConfig;
101 1
                break;
102
            }
103
        }
104
105 5
        if (! $normalizedPath) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $normalizedPath of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
106 4
            if (is_readable($this->getExamplePathFromSource($filename))) {
107 1
                $normalizedPath = $this->getExamplePathFromSource($filename);
108 3
            } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) {
109 1
                $normalizedPath = $this->getExamplePathFromExampleDirectory($filename);
110 2
            } elseif (is_readable($filename)) {
111 1
                $normalizedPath = $filename;
112
            }
113
        }
114
115 5
        return ($normalizedPath && is_readable($normalizedPath)) ? file($normalizedPath) : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression $normalizedPath of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
116
    }
117
118
    /**
119
     * Get example filepath based on the example directory inside your project.
120
     */
121 1
    private function getExamplePathFromExampleDirectory(string $file): string
122
    {
123 1
        return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file;
124
    }
125
126
    /**
127
     * Returns a path to the example file in the given directory..
128
     */
129 1
    private function constructExamplePath(string $directory, string $file): string
130
    {
131 1
        return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file;
132
    }
133
134
    /**
135
     * Get example filepath based on sourcecode.
136
     */
137 1
    private function getExamplePathFromSource(string $file): string
138
    {
139 1
        return sprintf(
140 1
            '%s%s%s',
141 1
            trim($this->getSourceDirectory(), '\\/'),
142 1
            DIRECTORY_SEPARATOR,
143 1
            trim($file, '"')
144
        );
145
    }
146
}
147