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/Profile.php (3 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\FileSystem\File;
8
use Ffcms\Core\Helper\Type\Any;
9
use Ffcms\Core\Helper\Type\Arr;
10
use Ffcms\Core\Helper\Type\Str;
11
use Ffcms\Core\Interfaces\iProfile;
12
13
/**
14
 * Class Profile. Active record model for user profile data store
15
 * @package Apps\ActiveRecord
16
 * @property int $id
17
 * @property int $user_id
18
 * @property string $nick
19
 * @property int $sex
20
 * @property string $birthday
21
 * @property string $city
22
 * @property string $hobby
23
 * @property int $rating
24
 * @property string $phone
25
 * @property string $url
26
 * @property array $custom_data
27
 * @property string $created_at
28
 * @property string $updated_at
29
 * @property User $user
30
 */
31
class Profile extends ActiveModel implements iProfile
32
{
33
    protected $casts = [
34
        'id' => 'integer',
35
        'user_id' => 'integer',
36
        'nick' => 'string',
37
        'sex' => 'integer', // tinyInteger 0|1|2
38
        'birthday' => 'string',
39
        'city' => 'string',
40
        'hobby' => 'string',
41
        'rating' => 'integer',
42
        'phone' => 'string',
43
        'url' => 'string',
44
        'custom_data' => 'serialize'
45
    ];
46
47
    /**
48
     * Get user profile via user_id like object (!!! profile.id !== user.id !!!)
49
     * @param int|null $userId
50
     * @return self|null
51
     */
52
    public static function identity($userId = null)
53
    {
54
        if ($userId === null) {
55
            $userId = MainApp::$Session->get('ff_user_id');
56
        }
57
58
        if ($userId === null || !Any::isInt($userId) || $userId < 1) {
59
            return null;
60
        }
61
62
        // check in cache
63
        if (MainApp::$Memory->get('profile.object.cache.' . $userId) !== null) {
64
            return MainApp::$Memory->get('profile.object.cache.' . $userId);
65
        }
66
67
        // find row
68
        $profile = self::where('user_id', $userId);
69
70
        // empty? lets return null
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
        if ($profile->count() !== 1) {
72
            return null;
73
        }
74
75
        $object = $profile->first();
76
        MainApp::$Memory->set('profile.object.cache.' . $userId, $object);
77
78
        return $object;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $object also could return the type Ffcms\Core\Arch\ActiveModel which is incompatible with the return type mandated by Ffcms\Core\Interfaces\iProfile::identity() of Ffcms\Core\Interfaces\iProfile|null.
Loading history...
79
    }
80
81
    /**
82
     * Get user avatar full url for current object
83
     * @param string $type
84
     * @return string
85
     */
86
    public function getAvatarUrl($type = 'small')
87
    {
88
        $default = '/upload/user/avatar/' . $type . '/default.jpg';
89
        if (!Arr::in($type, ['small', 'big', 'medium'])) {
90
            return MainApp::$Alias->scriptUrl . $default;
91
        }
92
93
        $route = '/upload/user/avatar/' . $type . '/' . $this->user_id . '.jpg';
94
        if (File::exist($route)) {
95
            return MainApp::$Alias->scriptUrl . $route . '?mtime=' . File::mTime($route);
96
        }
97
98
        return MainApp::$Alias->scriptUrl . $default;
99
    }
100
101
    /**
102
     * Get user nickname. If is empty - return 'id+userId'
103
     * @return string
104
     */
105
    public function getNickname(): ?string
106
    {
107
        $userNick = $this->nick;
108
        if (!$userNick || Str::likeEmpty($userNick)) {
109
            $userNick = 'id' . $this->id;
110
        }
111
112
        return $userNick;
113
    }
114
115
    /**
116
     * Get user active record object relation
117
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
118
     */
119
    public function user()
120
    {
121
        return $this->belongsTo(User::class, 'user_id');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->belongsTo(...User::class, 'user_id') returns the type Illuminate\Database\Eloquent\Relations\BelongsTo which is incompatible with the return type mandated by Ffcms\Core\Interfaces\iProfile::User() of Ffcms\Core\Interfaces\iUser|null.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
122
    }
123
}
124