Issues (20)

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/Device.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 App\Models;
4
5
use App\Support\Traits\Eloquent\DeviceModelAttribute;
6
use Iatstuti\Database\Support\NullableFields;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Request;
9
10
class Device extends Model
11
{
12
    use DeviceModelAttribute, NullableFields;
13
14
    /**
15
     * The accessors to append to the model's array form.
16
     *
17
     * @var array
18
     */
19
    protected $appends = [
20
        'device_model', 'push_enabled',
21
    ];
22
23
    /**
24
     * The attributes that are mass assignable.
25
     *
26
     * @var array
27
     */
28
    protected $fillable = [
29
        'tdid', 'did', 'os', 'os_version', 'platform', 'model', 'name',
30
        'jailbroken', 'carrier', 'locale', 'network', 'ssid',
31
        'push_token', 'idfa', 'idfv', 'screen_width', 'screen_height',
32
        'screen_scale', 'timezone_gmt',
33
    ];
34
35
    /**
36
     * The attributes that should be mutated to dates.
37
     *
38
     * @var array
39
     */
40
    protected $dates = ['last_login_at'];
41
42
    /**
43
     * The attributes that should be cast to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [
48
        'jailbroken' => 'boolean',
49
        'screen_width' => 'integer',
50
        'screen_height' => 'integer',
51
        'screen_scale' => 'float',
52
        'timezone_gmt' => 'integer',
53
        'login_count' => 'integer',
54
    ];
55
56
    /**
57
     * The attributes that should be saved as null when empty.
58
     *
59
     * @var array
60
     */
61
    protected $nullable = [
62
        'did', 'model', 'name', 'carrier', 'locale', 'network', 'ssid',
63
        'push_token', 'idfa', 'idfv', 'last_login_ip', 'registered_ip',
64
    ];
65
66
    /**
67
     * The model's attributes.
68
     *
69
     * @var array
70
     */
71
    protected $attributes = [
72
        'jailbroken' => 0,
73
        'screen_width' => 0,
74
        'screen_height' => 0,
75
        'screen_scale' => 0,
76
        'timezone_gmt' => 0,
77
        'login_count' => 0,
78
    ];
79
80
    /**
81
     * The device that matches the current app client.
82
     *
83
     * @var static|bool
84
     */
85
    protected static $clientDevice = false;
86
87
    /**
88
     * Get the `push_enabled` attribute.
89
     *
90
     * @return bool
91
     */
92
    public function getPushEnabledAttribute()
93
    {
94
        return ! is_null($this->push_token);
95
    }
96
97
    /**
98
     * Find a Device instance.
99
     *
100
     * @param  string  $tdid
101
     * @return static|null
102
     */
103
    public static function findByTdid($tdid)
104
    {
105
        return ! empty($tdid) ? static::where('tdid', $tdid)->first() : null;
106
    }
107
108
    /**
109
     * Fetch device id for the given tdid.
110
     *
111
     * @param  string  $tdid
112
     * @return int|null
113
     */
114
    public static function fetchDeviceIdForTdid($tdid)
115
    {
116
        return static::where('tdid', $tdid)->value('id');
117
    }
118
119
    /**
120
     * Get the device for the current app client.
121
     *
122
     * @return static|null
123
     */
124
    public static function getClientDevice()
125
    {
126
        if (false === static::$clientDevice) {
127
            static::$clientDevice = static::findByTdid(app('client')->tdid);
128
        }
129
130
        return static::$clientDevice;
131
    }
132
133
    /**
134
     * Set the device for the current app client.
135
     *
136
     * @param  static  $device
137
     * @return static
138
     */
139
    public static function setClientDevice($device)
140
    {
141
        return static::$clientDevice = $device;
142
    }
143
144
    /**
145
     * Get the id for the client device.
146
     *
147
     * @return int|null
148
     */
149
    public static function getClientDeviceId()
150
    {
151
        if ($device = static::getClientDevice()) {
152
            return $device->id;
153
        }
154
    }
155
156
    /**
157
     * Update or create a Device instance.
158
     *
159
     * @param  array  $data
160
     * @return static
161
     *
162
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
163
     */
164
    public static function touchDevice(array $data)
165
    {
166
        $tdid = array_get($data, 'tdid');
167
168
        if (empty($tdid) || $tdid !== app('client')->tdid) {
169
            abort(403);
170
        }
171
172
        $device = static::firstOrNew(compact('tdid'));
173
174
        if (isset($data['screen_size']) && str_contains($data['screen_size'], 'x')) {
175
            $screenSize = explode('x', $data['screen_size']);
176
            if (count($screenSize) == 2) {
177
                $data['screen_width'] = (int) $screenSize[0];
178
                $data['screen_height'] = (int) $screenSize[1];
179
            }
180
        }
181
182
        $device->fill($data);
183
184
        $device->login_count++;
185
        $device->last_login_at = $device->freshTimestamp();
186
        $device->last_login_ip = Request::ip();
187
188
        if (! $device->exists) {
189
            $device->registered_ip = $device->last_login_ip;
190
        }
191
192
        $device->save();
193
194
        return static::setClientDevice($device);
195
    }
196
197
    /**
198
     * Update push token for the device.
199
     *
200
     * @param  string  $tdid
201
     * @param  string|null $push_token
202
     * @return bool
203
     */
204
    public static function updatePushTokenForTdid($tdid, $push_token = null)
205
    {
206
        return static::where('tdid', $tdid)->update(compact('push_token'));
207
    }
208
209
    /**
210
     * Get DeviceApp models.
211
     *
212
     * @return \Illuminate\Support\Collection
213
     */
214
    public function getDeviceApps()
215
    {
216
        return DeviceApp::findByDeviceId($this->id);
217
    }
218
219
    /**
220
     * Get UserDevice models.
221
     *
222
     * @param  bool  $withTrashed
223
     * @return mixed
224
     */
225
    public function getDeviceUsers($withTrashed = false)
226
    {
227
        return UserDevice::findByUserDevice(null, $this->id, $withTrashed);
228
    }
229
230
    /**
231
     * Get users to this device.
232
     *
233
     * @param  bool  $withTrashed
234
     * @return \Illuminate\Support\Collection
235
     */
236 View Code Duplication
    public function getUsers($withTrashed = false)
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...
237
    {
238
        return User::whereIn('id', function ($query) use ($withTrashed) {
239
            $query->select('user_id')->from('user_devices')->where('device_id', $this->id);
240
241
            if (! $withTrashed) {
242
                $query->where('deleted_at', null);
243
            }
244
        })->get();
245
    }
246
}
247