Issues (111)

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.

app/Models/Notification.php (1 issue)

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
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * App\Models\Notification
10
 *
11
 * @property integer $notifications_id
12
 * @property string $title
13
 * @property string $body
14
 * @property string $source
15
 * @property string $checksum
16
 * @property string $datetime
17
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\NotificationAttrib[] $attribs
18
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereNotificationsId($value)
19
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereTitle($value)
20
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereBody($value)
21
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereSource($value)
22
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereChecksum($value)
23
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification whereDatetime($value)
24
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification isUnread()
25
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification isArchived($user)
26
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification limit()
27
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification source()
28
 * @mixin \Eloquent
29
 */
30
class Notification extends Model
31
{
32
33
    /**
34
     * Indicates if the model should be timestamped.
35
     *
36
     * @var bool
37
     */
38
    public $timestamps = false;
39
    /**
40
     * The table associated with the model.
41
     *
42
     * @var string
43
     */
44
    protected $table = 'notifications';
45
    /**
46
     * The primary key column name.
47
     *
48
     * @var string
49
     */
50
    protected $primaryKey = 'notifications_id';
51
52
    // ---- Helper Functions ----
53
54
    /**
55
     * Mark this notification as read or unread
56
     *
57
     * @param bool $enabled
58
     * @return bool
59
     */
60 1
    public function markRead($enabled = true)
61
    {
62 1
        return $this->setAttrib('read', $enabled);
63
    }
64
65
    /**
66
     * Mark this notification as sticky or unsticky
67
     *
68
     * @var bool $enabled
69
     * @return bool
70
     */
71
    public function markSticky($enabled = true)
72
    {
73
        return $this->setAttrib('sticky', $enabled);
74
    }
75
76
    /**
77
     * @param $name
78
     * @param $enabled
79
     * @return bool
80
     */
81 1
    private function setAttrib($name, $enabled)
82
    {
83 1
        if ($enabled === true) {
84 1
            $read = new NotificationAttrib;
85 1
            $read->user_id = \Auth::user()->user_id;
86 1
            $read->key = $name;
87 1
            $read->value = 1;
88 1
            $this->attribs()->save($read);
89 1
            return true;
90
        } else {
91
            return $this->attribs()->where('key', $name)->delete();
92
        }
93
    }
94
95
    // ---- Define Scopes ----
96
97
    /**
98
     * @param Builder $query
99
     * @return mixed
100
     */
101 1
    public function scopeIsUnread(Builder $query)
102
    {
103 1
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->source()->whereNull('notifications_attribs.user_id')->orWhere(['key' => 'sticky', 'value' => 1])->limit();
104
    }
105
106
    /**
107
     * @param Builder $query
108
     * @param User $user
109
     * @return mixed
110
     */
111 1
    public function scopeIsArchived(Builder $query, User $user)
112
    {
113 1
        $user_id = $user->user_id;
114 1
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->source()->where('notifications_attribs.user_id', $user_id)->where(['key' => 'read', 'value' => 1])->limit();
115
    }
116
117
    /**
118
     * @param Builder $query
119
     * @return $this
120
     */
121 1
    public function scopeLimit(Builder $query)
122
    {
123 1
        return $query->select('notifications.*', 'key', 'users.username');
0 ignored issues
show
The method select() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean createSelectWithConstraint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
124
    }
125
126
    /**
127
     * @param Builder $query
128
     * @return Builder|static
129
     */
130 1
    public function scopeSource(Builder $query)
131
    {
132 1
        return $query->leftJoin('users', 'notifications.source', '=', 'users.user_id');
133
    }
134
135
    // ---- Define Relationships ----
136
137
    /**
138
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
139
     */
140 1
    public function attribs()
141
    {
142 1
        return $this->hasMany('App\Models\NotificationAttrib', 'notifications_id', 'notifications_id');
143
    }
144
}
145