Issues (632)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

Apps/ActiveRecord/User.php (4 issues)

1
<?php
2
3
namespace Apps\ActiveRecord;
4
5
use Ffcms\Core\App as MainApp;
6
use Ffcms\Core\Arch\ActiveModel;
7
use Ffcms\Core\Helper\Type\Any;
8
use Ffcms\Core\Helper\Type\Str;
9
use Ffcms\Core\Interfaces\iUser;
10
use Ffcms\Core\Traits\SearchableTrait;
11
12
/**
13
 * Class User. Active record model for user auth data
14
 * @package Apps\ActiveRecord
15
 * @property int $id
16
 * @property string $email
17
 * @property string $password
18
 * @property int $role_id
19
 * @property string $approve_token
20
 * @property string $created_at
21
 * @property string $updated_at
22
 * @property WallPost $wall
23
 * @property Profile|null $profile
24
 * @property Role $role
25
 * @property UserLog $log
26
 * @property UserProvider $provider
27
 */
28
class User extends ActiveModel implements iUser
29
{
30
    use SearchableTrait;
31
32
    protected $casts = [
33
        'id' => 'integer',
34
        'email' => 'string',
35
        'role_id' => 'integer',
36
        'approve_token' => 'string'
37
    ];
38
39
    protected $searchable = [
40
        'columns' => [
41
            'email' => 3,
42
            'nick' => 2
43
        ],
44
        'joins' => [
45
            'profiles' => ['users.id', 'profiles.user_id']
46
        ]
47
    ];
48
49
    private $openidProvider;
50
51
    /**
52
     * Get user object relation. If $user_id is null - get current session user
53
     * @param string|int|null $id
54
     * @return self|null
55
     */
56
    public static function identity(?string $id = null): ?self
57
    {
58
        if (!$id) {
59
            $id = MainApp::$Session->get('ff_user_id');
60
        }
61
62
        // check if id is looks like integer
63
        if (!Any::isInt($id) || (int)$id < 1) {
64
            return null;
65
        }
66
67
        // check in memory cache object
68
        if (MainApp::$Memory->get('user.object.cache.' . $id)) {
69
            return MainApp::$Memory->get('user.object.cache.' . $id);
70
        }
71
72
        // not founded in memory? lets make query
73
        $user = self::with(['profile', 'role'])
74
            ->find($id);
75
76
        // store cache and return object
77
        MainApp::$Memory->set('user.object.cache.' . $user->id, $user);
78
        return $user;
79
    }
80
81
    /**
82
     * Get current user id if auth
83
     * @return int|null
84
     */
85
    public function getId(): ?int
86
    {
87
        return (int)$this->id;
88
    }
89
90
    /**
91
     * Get user param
92
     * @param string $param
93
     * @param null|string $defaultValue
94
     * @return string|int|null
95
     */
96
    public function getParam(string $param, ?string $defaultValue = null): ?string
97
    {
98
        return $this->{$param} ?? $defaultValue;
99
    }
100
101
    /**
102
     * Check if current user session is auth
103
     * @return bool
104
     */
105
    public static function isAuth(): bool
106
    {
107
        // get data from session
108
        $sessionUserId = (int)MainApp::$Session->get('ff_user_id', 0);
109
110
        // check if session contains user id data
111
        if ($sessionUserId < 1) {
112
            return false;
113
        }
114
115
        // find user identity
116
        $identity = self::identity($sessionUserId);
117
        if (!$identity) { // check if this $id exist
0 ignored issues
show
$identity is of type Apps\ActiveRecord\User, thus it always evaluated to true.
Loading history...
118
            MainApp::$Session->invalidate(); // destory session data - it's not valid!
119
            return false;
120
        }
121
122
        // check if user is approved. Default value: 0, can be null, '' or the same.
123
        if ($identity->approve_token) {
124
            return false;
125
        }
126
127
        return ($identity->id > 0 && $identity->id === $sessionUserId);
128
    }
129
130
    /**
131
     * Check if user with $id exist
132
     * @param string|int|null $id
133
     * @return bool
134
     */
135
    public static function isExist(?string $id = null): bool
136
    {
137
        if (!$id || !Any::isInt($id)) {
138
            return false;
139
        }
140
141
        $find = MainApp::$Memory->get('user.counter.cache.' . $id);
142
        if (!$find) {
143
            $find = self::where('id', $id)->count();
144
            MainApp::$Memory->set('user.counter.cache.' . $id, $find);
145
        }
146
147
        return (int)$find === 1;
148
    }
149
150
    /**
151
     * Check if use with $email is exist
152
     * @param string $email
153
     * @return bool
154
     */
155
    public static function isMailExist(?string $email = null): bool
156
    {
157
        if (!Any::isStr($email) || !Str::isEmail($email)) {
0 ignored issues
show
It seems like $email can also be of type null; however, parameter $string of Ffcms\Core\Helper\Type\Str::isEmail() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

157
        if (!Any::isStr($email) || !Str::isEmail(/** @scrutinizer ignore-type */ $email)) {
Loading history...
158
            return false;
159
        }
160
161
        return self::where('email', $email)->count() > 0;
162
    }
163
164
    /**
165
     * Get user person like a object via email
166
     * @param string|null $email
167
     * @return null|self
168
     */
169
    public static function getIdentityViaEmail(?string $email = null)
170
    {
171
        if (!self::isMailExist($email)) {
172
            return null;
173
        }
174
175
        return self::where('email', $email)->first();
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::where('email', $email)->first() also could return the type Ffcms\Core\Arch\ActiveModel which is incompatible with the return type mandated by Ffcms\Core\Interfaces\iUser::getIdentityViaEmail() of Ffcms\Core\Interfaces\iUser|null.
Loading history...
176
    }
177
178
    /**
179
     * Get user wall post relation
180
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
181
     */
182
    public function wall()
183
    {
184
        return $this->hasMany(WallPost::class, 'target_id');
185
    }
186
187
    /**
188
     * Get user role relation object.
189
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
190
     */
191
    public function role()
192
    {
193
        return $this->hasOne(Role::class, 'id', 'role_id');
194
    }
195
196
    /**
197
     * Get user profile relation object.
198
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
199
     */
200
    public function profile()
201
    {
202
        return $this->hasOne(Profile::class, 'user_id', 'id');
203
    }
204
205
    /**
206
     * Get user logs relation object
207
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
208
     */
209
    public function log()
210
    {
211
        return $this->hasMany(UserLog::class, 'user_id');
212
    }
213
214
    /**
215
     * Get user social providers data
216
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
217
     */
218
    public function provider()
219
    {
220
        return $this->hasMany(UserProvider::class, 'user_id');
221
    }
222
223
    /**
224
     * Check if target user in blacklist
225
     * @param string|int|null $target
226
     * @return bool
227
     */
228
    public function inBlacklist(?string $target = null): bool
229
    {
230
        if (!$target || (int)$target < 1) {
231
            return false;
232
        }
233
234
        return Blacklist::have($this->getId(), $target);
0 ignored issues
show
$target of type string is incompatible with the type integer expected by parameter $targetId of Apps\ActiveRecord\Blacklist::have(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

234
        return Blacklist::have($this->getId(), /** @scrutinizer ignore-type */ $target);
Loading history...
235
    }
236
237
    /**
238
     * Set openID library dependence object. Do not use this function, if you have no idia how it work
239
     * @param $provider
240
     */
241
    public function setOpenidInstance($provider): void
242
    {
243
        $this->openidProvider = $provider;
244
    }
245
246
    /**
247
     * Get openid provider library. Default - hybridauth
248
     * @return \Hybrid_Auth
249
     */
250
    public function getOpenidInstance()
251
    {
252
        return $this->openidProvider;
253
    }
254
}
255