Issues (51)

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.

build/refreshReadmeTable.php (2 issues)

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
declare(strict_types=1);
4
5
require_once __DIR__ . '/../vendor/autoload.php';
6
7
$directory = new RecursiveDirectoryIterator($baseFolder = './src/Standards/BestIt/Sniffs');
8
$iterator = new RecursiveIteratorIterator($directory);
9
$regexIterator = new RegexIterator($iterator, '/^.+Sniff\.php$/i', RecursiveRegexIterator::GET_MATCH);
10
11
outputCodesTable(handleFiles($regexIterator, $baseFolder));
12
13
/**
14
 * Returns the constants of the class.
15
 *
16
 * @param string $fullQualifiedClassName
17
 *
18
 * @return array
19
 */
20
function getConstants(string $fullQualifiedClassName): array
21
{
22
    $reflection = new ReflectionClass($fullQualifiedClassName);
23
    $constants = $reflection->getConstants();
24
25
    return !$reflection->isAbstract() ? $constants : [];
26
}
27
28
/**
29
 * Returns the description for the code constant by parsing the doc block.
30
 *
31
 * @throws DomainException If there is no valid doc block.
32
 *
33
 * @param string $fullQualifiedClassName
34
 * @param string $constant
35
 *
36
 * @return string
37
 */
38
function getCodeDesc(string $fullQualifiedClassName, string $constant): string
39
{
40
    $constReflection = new ReflectionClassConstant($fullQualifiedClassName, $constant);
41
42
    // $re = ;
43
    if (!$docComment = $constReflection->getDocComment()) {
44
        throw new DomainException(
45
            sprintf('There should be a doc block for %s:%s', $fullQualifiedClassName, $constant)
46
        );
47
    }
48
49
    if (!preg_match('~/\*\*\s(.*)\s~m', $docComment, $matches)) {
50
        throw new DomainException(
51
            sprintf(
52
                'There should be a doc block with summary for %s:%s',
53
                $fullQualifiedClassName,
54
                $constant
55
            )
56
        );
57
    }
58
59
    return trim($matches[1], '* ');
60
}
61
62
/**
63
 * Iterates thru the base folder and parses the sniff files for the documentation.
64
 *
65
 * @param Iterator $regexIterator
66
 * @param string $baseFolder
67
 *
68
 * @return array
69
 */
70
function handleFiles(Iterator $regexIterator, string $baseFolder): array
71
{
72
    $codes = [];
73
74
    foreach ($regexIterator as $file) {
75
        [$file] = $file;
76
77
        $simpleClassName = str_replace([$baseFolder . DIRECTORY_SEPARATOR, '.php', 'Sniff'], '', $file);
78
        $fullQualifiedClassName = 'BestIt\\Sniffs\\' . str_replace('/', '\\', $simpleClassName) . 'Sniff';
79
80
        $hasSuppresses = (bool) preg_match_all(
81
            '/->isSniffSuppressed\((?P<code>\s*.*\s*)\)/mU',
82
            file_get_contents($file),
83
            $suppresses
84
        );
85
86
        try {
87
            $constants = getConstants($fullQualifiedClassName);
88
89
            foreach ($constants as $constant => $constantValue) {
90
                if (substr($constant, 0, 5) === 'CODE_') {
91
                    $sniffDesc = getCodeDesc($fullQualifiedClassName, $constant);
92
93
                    $sniffRule = sprintf(
94
                        'BestIt.%s.%s',
95
                        str_replace(DIRECTORY_SEPARATOR, '.', $simpleClassName),
96
                        $constantValue
97
                    );
98
99
                    $codes[$sniffRule] = [$sniffDesc, $hasSuppresses];
100
101
                    if ($hasSuppresses) {
102
                        if (!array_filter($suppresses['code'])) {
103
                            $codes[$sniffRule][1] = 'yes by class';
104
                        } else {
105
                            $codeHasMatchingSuppress = false;
106
107
                            foreach ($suppresses['code'] as $foundSuppress) {
108
                                $foundSuppressValue = str_replace(['self::', 'static::'], '', $foundSuppress);
109
110
111
                                if (
112
                                    $codeHasMatchingSuppress = in_array(
113
                                        $foundSuppressValue,
114
                                        [$constant, $constantValue],
115
                                        true
116
                                    )
117
                                ) {
118
                                    $codes[$sniffRule][1] = 'yes';
119
120
                                    break;
121
                                }
122
                            }
123
124
                            if (!$codeHasMatchingSuppress) {
125
                                $codes[$sniffRule][1] = false;
126
                            }
127
                        }
128
                    }
129
                }
130
            }
131
        } catch (ReflectionException $e) {
132
            echo $e;
133
        }
134
    }
135
    return $codes;
136
}
137
138
/**
139
 * Saves the table in the table.md and outputs it.
140
 *
141
 * @param array $codes
142
 *
143
 * @return void
144
 */
145
function outputCodesTable(array $codes): void
146
{
147
    ksort($codes);
148
149
    file_put_contents(
150
        $tmpFile = __DIR__ . DIRECTORY_SEPARATOR . 'table.md',
151
        <<<EOD
152
| Sniff | Description | suppressable |
153
| ----- | ----------- | ------------ |
154
EOD
155
    );
156
157
    foreach ($codes as $code => $codeRule) {
158
        [$description, $hasSuppresses] = $codeRule;
0 ignored issues
show
The variable $description does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hasSuppresses does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
159
160
        file_put_contents(
161
            $tmpFile,
162
            sprintf(
163
                "\n| %s | %s | %s |",
164
                $code,
165
                $description,
166
                $hasSuppresses ?: 'no'
167
            ),
168
            FILE_APPEND
169
        );
170
    }
171
172
    echo file_get_contents($tmpFile);
173
}
174