Issues (847)

Security Analysis    not enabled

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.

inc/ErrorHandler.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
namespace dokuwiki;
4
5
use dokuwiki\Exception\FatalException;
6
7
/**
8
 * Manage the global handling of errors and exceptions
9
 *
10
 * Developer may use this to log and display exceptions themselves
11
 */
12
class ErrorHandler
13
{
14
    /**
15
     * Register the default error handling
16
     */
17
    public static function register()
18
    {
19
        if (!defined('DOKU_UNITTEST')) {
20
            set_exception_handler([ErrorHandler::class, 'fatalException']);
21
            register_shutdown_function([ErrorHandler::class, 'fatalShutdown']);
22
        }
23
    }
24
25
    /**
26
     * Default Exception handler to show a nice user message before dieing
27
     *
28
     * The exception is logged to the error log
29
     *
30
     * @param \Throwable $e
31
     */
32
    public static function fatalException($e)
33
    {
34
        $plugin = self::guessPlugin($e);
35
        $title = hsc(get_class($e) . ': ' . $e->getMessage());
36
        $msg = 'An unforeseen error has occured. This is most likely a bug somewhere.';
37
        if ($plugin) $msg .= ' It might be a problem in the ' . $plugin . ' plugin.';
0 ignored issues
show
Bug Best Practice introduced by
The expression $plugin of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
38
        $logged = self::logException($e)
39
            ? 'More info has been written to the DokuWiki error log.'
40
            : $e->getFile() . ':' . $e->getLine();
41
42
        echo <<<EOT
43
<!DOCTYPE html>
44
<html>
45
<head><title>$title</title></head>
46
<body style="font-family: Arial, sans-serif">
47
    <div style="width:60%; margin: auto; background-color: #fcc;
48
                border: 1px solid #faa; padding: 0.5em 1em;">
49
        <h1 style="font-size: 120%">$title</h1>
50
        <p>$msg</p>
51
        <p>$logged</p>
52
    </div>
53
</body>
54
</html>
55
EOT;
56
    }
57
58
    /**
59
     * Convenience method to display an error message for the given Exception
60
     *
61
     * @param \Throwable $e
62
     * @param string $intro
63
     */
64
    public static function showExceptionMsg($e, $intro = 'Error!')
65
    {
66
        $msg = hsc($intro) . '<br />' . hsc(get_class($e) . ': ' . $e->getMessage());
67
        if (self::logException($e)) $msg .= '<br />More info is available in the error log.';
68
        msg($msg, -1);
69
    }
70
71
    /**
72
     * Last resort to handle fatal errors that still can't be caught
73
     */
74
    public static function fatalShutdown()
75
    {
76
        $error = error_get_last();
77
        // Check if it's a core/fatal error, otherwise it's a normal shutdown
78
        if (
79
            $error !== null &&
80
            in_array(
81
                $error['type'],
82
                [
83
                    E_ERROR,
84
                    E_CORE_ERROR,
85
                    E_COMPILE_ERROR,
86
                ]
87
            )
88
        ) {
89
            self::fatalException(
90
                new FatalException($error['message'], 0, $error['type'], $error['file'], $error['line'])
91
            );
92
        }
93
    }
94
95
    /**
96
     * Log the given exception to the error log
97
     *
98
     * @param \Throwable $e
99
     * @return bool false if the logging failed
100
     */
101
    public static function logException($e)
102
    {
103
        return Logger::getInstance()->log(
104
            get_class($e) . ': ' . $e->getMessage(),
105
            $e->getTraceAsString(),
106
            $e->getFile(),
107
            $e->getLine()
108
        );
109
    }
110
111
    /**
112
     * Checks the the stacktrace for plugin files
113
     *
114
     * @param \Throwable $e
115
     * @return false|string
116
     */
117
    protected static function guessPlugin($e)
118
    {
119
        if (preg_match('/lib\/plugins\/(\w+)\//', str_replace('\\', '/', $e->getFile()), $match)) {
120
            return $match[1];
121
        }
122
123
        foreach ($e->getTrace() as $line) {
124
            if (
125
                isset($line['class']) &&
126
                preg_match('/\w+?_plugin_(\w+)/', $line['class'], $match)
127
            ) {
128
                return $match[1];
129
            }
130
131
            if (
132
                isset($line['file']) &&
133
                preg_match('/lib\/plugins\/(\w+)\//', str_replace('\\', '/', $line['file']), $match)
134
            ) {
135
                return $match[1];
136
            }
137
        }
138
139
        return false;
140
    }
141
}
142