Issues (2)

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.

Plugin.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
3
namespace VojtaSvoboda\ErrorLogger;
4
5
use Backend\Facades\BackendAuth;
6
use Config;
7
use Log;
8
use VojtaSvoboda\ErrorLogger\Models\Settings;
9
use Monolog\Formatter\LineFormatter;
10
use Monolog\Handler\NativeMailerHandler;
11
use Monolog\Handler\NewRelicHandler;
12
use Monolog\Handler\SlackHandler;
13
use Monolog\Handler\SyslogHandler;
14
use Monolog\Logger;
15
use System\Classes\PluginBase;
16
17
/**
18
 * Error Logger Plugin Information File
19
 */
20
class Plugin extends PluginBase
21
{
22
    /**
23
     * Returns information about this plugin.
24
     *
25
     * @return array
26
     */
27
    public function pluginDetails()
28
    {
29
        return [
30
            'name' => 'vojtasvoboda.errorlogger::lang.plugin.name',
31
            'description' => 'vojtasvoboda.errorlogger::lang.plugin.description',
32
            'author' => 'Vojta Svoboda',
33
            'icon' => 'icon-bug',
34
        ];
35
    }
36
37
    public function registerSettings()
38
    {
39
        return [
40
            'config' => [
41
                'label' => 'vojtasvoboda.errorlogger::lang.settings.label',
42
                'category' => 'system::lang.system.categories.system',
43
                'icon' => 'icon-bug',
44
                'description' => 'vojtasvoboda.errorlogger::lang.settings.description',
45
                'class' => 'VojtaSvoboda\ErrorLogger\Models\Settings',
46
                'permissions' => ['vojtasvoboda.errorlogger.*'],
47
                'order' => 610,
48
            ]
49
        ];
50
    }
51
52
    public function registerPermissions()
53
    {
54
        return [
55
            'vojtasvoboda.errorlogger.*' => [
56
                'tab' => 'vojtasvoboda.errorlogger::lang.permissions.tab',
57
                'label' => 'vojtasvoboda.errorlogger::lang.permissions.all.label'
58
            ]
59
        ];
60
    }
61
62
    /**
63
     * Boot plugin and register handlers
64
     */
65
    public function boot()
66
    {
67
        $isLaravel56OrUp = method_exists(\Illuminate\Log\Logger::class, 'getLogger');
68
        $monolog = $isLaravel56OrUp ? Log::getLogger() : Log::getMonolog();
69
70
        $this->setNativeMailerHandler($monolog);
71
        $this->setSlackHandler($monolog);
72
        $this->setSyslogHandler($monolog);
73
        $this->setNewrelicHandler($monolog);
74
    }
75
76
    /**
77
     * Set native mailer handler
78
     * 
79
     * Formatting lines example (use before pushHandler()):
80
     *   $formater = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n");
81
     *   $handler->setFormatter($formater);
82
     *
83
     * @param $monolog
84
     *
85
     * @return Logger
86
     */
87
    private function setNativeMailerHandler($monolog)
88
    {
89
        $required = ['nativemailer_enabled', 'nativemailer_email'];
90
        if (!$this->checkRequiredFields($required)) {
91
            return $monolog;
92
        }
93
94
        // disable when debug is true
95
        $debug = Settings::get('nativemailer_debug');
96
        if ($debug & Config::get('app.debug')) {
97
            return $monolog;
98
        }
99
100
        $email = Settings::get('nativemailer_email');
101
        $subject = Config::get('app.url') . ' - error report';
102
        $from = Config::get('mail.from.address');
103
        $level = Settings::get('nativemailer_level', 100);
104
        $handler = new NativeMailerHandler($email, $subject, $from, $level);
105
        $monolog->pushHandler($handler);
106
107
        return $monolog;
108
    }
109
110
    /**
111
     * Set handler for Slack messaging app
112
     *
113
     * @param $monolog
114
     *
115
     * @return Logger
116
     */
117
    private function setSlackHandler($monolog)
118
    {
119
        $required = ['slack_enabled', 'slack_token'];
120
        if (!$this->checkRequiredFields($required)) {
121
            return $monolog;
122
        }
123
124
        $token = Settings::get('slack_token');
125
        $channel = Settings::get('slack_channel', 'random');
126
        $username = Settings::get('slack_username', 'error-bot');
127
        $attachment = Settings::get('slack_attachment', false);
128
        $level = Settings::get('slack_level', 100);
129
        $handler = new SlackHandler($token, $channel, $username, $attachment, null, $level);
130
        $monolog->pushHandler($handler);
131
132
        return $monolog;
133
    }
134
135
    /**
136
     * Set handler for Syslog
137
     *
138
     * @param $monolog
139
     *
140
     * @return Logger
141
     */
142 View Code Duplication
    private function setSyslogHandler($monolog)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
    {
144
        $required = ['syslog_enabled', 'syslog_ident', 'syslog_facility'];
145
        if (!$this->checkRequiredFields($required)) {
146
            return $monolog;
147
        }
148
149
        $ident = Settings::get('syslog_ident');
150
        $facility = Settings::get('syslog_facility');
151
        $level = Settings::get('syslog_level', 100);
152
        $handler = new SyslogHandler($ident, $facility, $level);
153
        $monolog->pushHandler($handler);
154
155
        return $monolog;
156
    }
157
158
    /**
159
     * Set handler for New Relic
160
     *
161
     * @param $monolog
162
     *
163
     * @return Logger
164
     */
165 View Code Duplication
    private function setNewrelicHandler($monolog)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        $required = ['newrelic_enabled', 'newrelic_appname'];
168
        if (!$this->checkRequiredFields($required)) {
169
            return $monolog;
170
        }
171
172
        $appname = Settings::get('newrelic_appname');
173
        $level = Settings::get('newrelic_level', 100);
174
        $bubble = true;
175
        $handler = new NewRelicHandler($level, $bubble, $appname);
176
        $monolog->pushHandler($handler);
177
178
        return $monolog;
179
    }
180
181
    /**
182
     * Check each required field if exist and not empty
183
     *
184
     * @param array $fields
185
     *
186
     * @return bool
187
     */
188
    private function checkRequiredFields(array $fields)
189
    {
190
        foreach ($fields as $field) {
191
            $value = Settings::get($field);
192
            if (!$value || empty($value)) {
193
                return false;
194
            }
195
        }
196
197
        return true;
198
    }
199
}
200