Issues (33)

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/Traits/LogsActivity.php (5 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 Spatie\Activitylog\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphMany;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use Illuminate\Support\Arr;
9
use Illuminate\Support\Collection;
10
use Spatie\Activitylog\ActivityLogger;
11
use Spatie\Activitylog\ActivitylogServiceProvider;
12
use Spatie\Activitylog\ActivityLogStatus;
13
14
trait LogsActivity
15
{
16
    use DetectsChanges;
17
18
    protected $enableLoggingModelsEvents = true;
19 216
20
    protected static function bootLogsActivity()
21
    {
22
        static::eventsToBeRecorded()->each(function ($eventName) {
23 212
            return static::$eventName(function (Model $model) use ($eventName) {
24 12
                if (! $model->shouldLogEvent($eventName)) {
25
                    return;
26
                }
27 208
28
                $description = $model->getDescriptionForEvent($eventName);
29 208
30
                $logName = $model->getLogNameToUse($eventName);
31 208
32
                if ($description == '') {
33
                    return;
34
                }
35 208
36
                $attrs = $model->attributeValuesToBeLogged($eventName);
37 208
38 4
                if ($model->isLogEmpty($attrs) && ! $model->shouldSubmitEmptyLogs()) {
39
                    return;
40
                }
41 208
42 208
                $logger = app(ActivityLogger::class)
43 208
                    ->useLog($logName)
44 208
                    ->performedOn($model)
45
                    ->withProperties($attrs);
46 208
47 8
                if (method_exists($model, 'tapActivity')) {
48
                    $logger->tap([$model, 'tapActivity'], $eventName);
49
                }
50 208
51 216
                $logger->log($description);
52 216
            });
53 216
        });
54
    }
55 72
56
    public function shouldSubmitEmptyLogs(): bool
57 72
    {
58
        return ! isset(static::$submitEmptyLogs) ? true : static::$submitEmptyLogs;
59
    }
60 208
61
    public function isLogEmpty($attrs): bool
62 208
    {
63
        return empty($attrs['attributes'] ?? []) && empty($attrs['old'] ?? []);
64
    }
65 12
66
    public function disableLogging()
67 12
    {
68
        $this->enableLoggingModelsEvents = false;
69 12
70
        return $this;
71
    }
72 4
73
    public function enableLogging()
74 4
    {
75
        $this->enableLoggingModelsEvents = true;
76 4
77
        return $this;
78
    }
79 28
80
    public function activities(): MorphMany
81 28
    {
82
        return $this->morphMany(ActivitylogServiceProvider::determineActivityModel(), 'subject');
0 ignored issues
show
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
83
    }
84 204
85
    public function getDescriptionForEvent(string $eventName): string
86 204
    {
87
        return $eventName;
88
    }
89 204
90
    public function getLogNameToUse(string $eventName = ''): string
0 ignored issues
show
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91 204
    {
92 4
        if (isset(static::$logName)) {
93
            return static::$logName;
94
        }
95 200
96
        return config('activitylog.default_log_name');
97
    }
98
99
    /*
100
     * Get the event names that should be recorded.
101 216
     */
102
    protected static function eventsToBeRecorded(): Collection
103 216
    {
104
        if (isset(static::$recordEvents)) {
105
            return collect(static::$recordEvents);
106
        }
107 216
108 216
        $events = collect([
109
            'created',
110
            'updated',
111
            'deleted',
112
        ]);
113 216
114 76
        if (collect(class_uses_recursive(static::class))->contains(SoftDeletes::class)) {
115
            $events->push('restored');
116
        }
117 216
118
        return $events;
119
    }
120 208
121
    public function attributesToBeIgnored(): array
122 208
    {
123 208
        if (! isset(static::$ignoreChangedAttributes)) {
124
            return [];
125
        }
126
127
        return static::$ignoreChangedAttributes;
128
    }
129 212
130
    protected function shouldLogEvent(string $eventName): bool
131 212
    {
132 8
        $logStatus = app(ActivityLogStatus::class);
133
134
        if (! $this->enableLoggingModelsEvents || $logStatus->disabled()) {
135 208
            return false;
136 24
        }
137
138
        if (! in_array($eventName, ['created', 'updated'])) {
139 208
            return true;
140 4
        }
141 4
142
        if (Arr::has($this->getDirty(), 'deleted_at')) {
0 ignored issues
show
It seems like getDirty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
143
            if ($this->getDirty()['deleted_at'] === null) {
0 ignored issues
show
It seems like getDirty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
144
                return false;
145
            }
146 208
        }
147
148
        //do not log update event if only ignored attributes are changed
149
        return (bool) count(Arr::except($this->getDirty(), $this->attributesToBeIgnored()));
0 ignored issues
show
It seems like getDirty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
150
    }
151
}
152