Issues (337)

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/component/Auth/Auth.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 Rudolf\Component\Auth;
4
5
use PDO;
6
7
class Auth
8
{
9
    /**
10
     * @var PDO
11
     */
12
    private $pdo;
13
14
    /**
15
     * @var string
16
     */
17
    private $prefix;
18
19
    /**
20
     * @var string
21
     */
22
    private $table;
23
24
    /**
25
     * @var Session
26
     */
27
    private $session;
28
29
    /**
30
     * Auth constructor.
31
     * @param PDO $pdo
32
     * @param string $prefix
33
     */
34
    public function __construct(PDO $pdo, $prefix = '')
35
    {
36
        $this->pdo = $pdo;
37
        $this->prefix = $prefix;
38
39
        $this->table = $this->prefix.'users';
40
41
        $this->session = new Session($pdo, $prefix, include CONFIG_ROOT.'/'.'auth.php');
42
    }
43
44
    /**
45
     * Login user.
46
     *
47
     * @param string $email
48
     * @param string $password
49
     *
50
     * @return int
51
     *             1 - logged in!
52
     *             2 - email not valid
53
     *             3 - password not valid
54
     *             4 - user not exist
55
     *             5 - email or password incorrect
56
     *             6 - account is inactive
57
     *             7 - unnamed error
58
     */
59
    public function login($email, $password)
60
    {
61
62
        #validation
63
        if (false === $this->validateEmail($email)) {
64
            return 2;
65
        }
66
67
        if (false === $this->validatePassword($password)) {
68
            return 3;
69
        }
70
71
        #get user data by email
72
        $userData = $this->getUserDataByEmail($email);
73
        if (false === $userData) {
74
            return 4;
75
        }
76
77
        #check password
78
        if (!password_verify($password, $userData['password'])) {
79
            return 5;
80
        }
81
82
        #check is user active
83
        if (false === $userData['active']) {
84
            return 6;
85
        }
86
87
        #create session
88
        if (false === $this->session->createSession($userData)) {
0 ignored issues
show
It seems like $userData defined by $this->getUserDataByEmail($email) on line 72 can also be of type boolean; however, Rudolf\Component\Auth\Session::createSession() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
89
            return 7;
90
        }
91
92
        return 1;
93
    }
94
95
    /**
96
     * Logout current user.
97
     *
98
     * @return bool
99
     */
100
    public function logout()
101
    {
102
        return $this->session->destroySession();
103
    }
104
105
    /**
106
     * Check is session exists.
107
     *
108
     * @return bool
109
     */
110
    public function check()
111
    {
112
        return $this->session->checkSession();
113
    }
114
115
    /**
116
     * Get logged user info.
117
     *
118
     * @param int|bool $uid User ID
119
     *                not set gives current logged user data
120
     *
121
     * @return array|bool
122
     */
123 View Code Duplication
    public function getUser($uid = 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...
124
    {
125
        if (false === $uid) {
126
            $uid = $this->session->getSessionUID();
127
        }
128
129
        $stmt = $this->pdo->prepare("
130
            SELECT id,
131
                   nick,
132
                   first_name,
133
                   surname,
134
                   email,
135
                   active,
136
                   dt
137
            FROM {$this->table}
138
            WHERE id = :uid
139
        ");
140
        $stmt->bindValue(':uid', $uid, \PDO::PARAM_INT);
141
        $stmt->execute();
142
143
        $data = $stmt->fetch(\PDO::FETCH_ASSOC);
144
        if (empty($data)) {
145
            return false;
146
        }
147
148
        return $data;
149
    }
150
151
    /**
152
     * Get password hash.
153
     *
154
     * @param string $password
155
     *
156
     * @return string
157
     */
158
    public function getPasswordHash($password)
159
    {
160
        return password_hash($password, PASSWORD_BCRYPT);
161
    }
162
163
    /**
164
     * Get user data by email.
165
     *
166
     * @param string $email
167
     *
168
     * @return array|bool
169
     */
170 View Code Duplication
    public function getUserDataByEmail($email)
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...
171
    {
172
        $stmt = $this->pdo->prepare("
173
            SELECT *
174
            FROM {$this->table}
175
            WHERE email = :email
176
        ");
177
        $stmt->bindValue(':email', $email, \PDO::PARAM_STR);
178
        $stmt->execute();
179
        $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
180
181
        if (empty($results[0])) {
182
            return false;
183
        }
184
185
        return $results[0];
186
    }
187
188
    /**
189
     * Validate email.
190
     *
191
     * @param string $email
192
     *
193
     * @return bool
194
     */
195
    public function validateEmail($email)
0 ignored issues
show
The parameter $email 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...
196
    {
197
        return true;
198
    }
199
200
    /**
201
     * Validate password.
202
     *
203
     * @param string $password
204
     *
205
     * @return bool
206
     */
207
    public function validatePassword($password)
0 ignored issues
show
The parameter $password 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...
208
    {
209
        return true;
210
    }
211
}
212