Issues (97)

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.

src/Observers/Changes.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 Audit\Observers;
4
5
// Deps
6
7
use Audit\Models\Change;
8
use Event;
9
use Route;
10
11
/**
12
 * Create a log of all model changing events
13
 */
14
class Changes
15
{
16
    /**
17
     * Only log the following events
18
     *
19
     * @param array
20
     */
21
    protected $supported = ['created', 'updated', 'deleted'];
22
23
    protected $action = false;
24
25
    /**
26
     * Handle all Eloquent model events
27
     *
28
     * @param string $event
29
     * @param array  $payload Contains:
30
     *                        -
31
     *                        Audit\Models\Base
32
     *                        $model
33
     */
34
    public function handle($event, $payload)
35
    {
36
        list($model) = $payload;
37
        if ($this->isToIgnore($model, $event)) {
38
            return;
39
        }
40
41
42
        // If `log_changes` was configed as a callable, see if this model event
43
        // should not be logged
44
        if ($check = \Illuminate\Support\Facades\Config::get('sitec.site.log_changes')) {
45
            if (is_bool($check) && !$check) {
46
                return;
47
            }
48
            // Get the admin acting on the record
49
            $admin =  $this->getUser();
50
            if (is_callable($check)) {
51
                if (!call_user_func($check, $model, $this->action, $admin)) {
52
                    return;
53
                }
54
            }
55
        } else {
56
            return;
57
        }
58
59
        // Check with the model itself to see if it should be logged
60
        if (method_exists($model, 'shouldLogChange')) {
61
            if (!$model->shouldLogChange($this->action)) {
62
                return;
63
            }
64
            // Default to not logging changes if there is no shouldLogChange()
65
        } else {
66
            return;
67
        }
68
        \Log::debug('[Audit] Log Changes: '.get_class($model));
69
        // \Log::debug('[Audit] Log Changes: '.print_r($event, true).print_r($payload, true));
70
71
        // Log the event
72
        Change::log($model, $this->action, $admin);
0 ignored issues
show
$this->action is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
    }
74
75
    protected function getUser()
76
    {
77
        return app('facilitador.user');
78
    }
79
80
    protected function isToIgnore($model, $event)
81
    {
82
        // Don't log changes to pivot models.  Even though a user may have initiated
83
        // this, it's kind of meaningless to them.  These events can happen when a
84
        // user messes with drag and drop positioning.
85
        if (!empty($this->getDontLog())) {
86
            foreach ($this->getDontLog() as $logClass) {
87
                if (is_a($model, $logClass)) {
88
                    return true;
89
                }
90
            }
91
        }
92
        if (!empty($this->getDontLogAlias())) {
93
            foreach ($this->getDontLogAlias() as $logClassAlias) {
94
                if (strpos($event, $logClassAlias) !== false) {
95
                    return true;
96
                }
97
            }
98
        }
99
100
        // Get the action of the event
101
        preg_match('#eloquent\.(\w+)#', $event, $matches);
102
        $this->action = $matches[1];
0 ignored issues
show
Documentation Bug introduced by
The property $action was declared of type boolean, but $matches[1] is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
103
        if (!in_array($this->action, $this->supported)) {
104
            return true;
105
        }
106
107
        return false;
108
    }
109
110
    protected function getDontLog()
111
    {
112
        return \Illuminate\Support\Facades\Config::get(
113
            'sitec.audit.dontLog',
114
            [
115
                \Aschmelyun\Larametrics\Models\LarametricsLog::class,
116
                \Illuminate\Database\Eloquent\Relations\Pivot::class,
117
            ]
118
        );
119
    }
120
121
    protected function getDontLogAlias()
122
    {
123
        return \Illuminate\Support\Facades\Config::get(
124
            'sitec.audit.dontLogAlias',
125
            [
126
                'Tracking\Models',
127
                'Analytics',
128
                'Spatie\Analytics',
129
                'Wnx\LaravelStats',
130
                'Aschmelyun\Larametrics\Models',
131
                'Laravel\Horizon',
132
                'Support\Models\Application',
133
                'Support\Models\Ardent',
134
                'Support\Models\Code',
135
            ]
136
        );
137
    }
138
}
139