Issues (42)

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/Controller/UsersController.php (8 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
 * CakeCMS Community
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Community
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Community".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Community\Controller;
17
18
use Core\Event\EventManager;
19
use Community\Model\Entity\User;
20
use Community\Model\Table\UsersTable;
21
22
/**
23
 * Class UsersController
24
 *
25
 * @package     Community\Controller
26
 * @property    UsersTable $Users
27
 */
28
class UsersController extends AppController
29
{
30
31
    /**
32
     * Default profile page action.
33
     *
34
     * @return  void
35
     *
36
     * @throws  \Aura\Intl\Exception
37
     */
38
    public function profile()
39
    {
40
        $userId = $this->Auth->user('id');
41
        if (!$userId) {
42
            $this->Flash->error(__d('community', 'You are not logged in'));
43
            $this->redirect($this->Auth->getConfig('loginAction'));
44
        }
45
46
        $this
47
            ->set('user', $this->Users->get($userId, ['contain' => 'Groups']))
48
            ->set('page_title', __d('community', 'Edit profile'));
49
    }
50
51
    /**
52
     * Activation user profile action.
53
     *
54
     * @param   null|int $id            User id.
55
     * @param   null|string $token      User activation token.
56
     * @return  \Cake\Http\Response|null
57
     *
58
     * @throws  \Aura\Intl\Exception
59
     */
60
    public function activate($id = null, $token = null)
61
    {
62
        $user = $this->_getUser($id, $token);
63
64 View Code Duplication
        if ($user === null) {
0 ignored issues
show
This code seems to be duplicated across 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...
65
            $this->Flash->error(__d('community', 'User was not found'));
66
            return $this->redirect(['action' => 'login']);
67
        }
68
69
        if ($user->status) {
70
            $this->Flash->error(__d(
71
                'community',
72
                '«{0}», you have already activated your profile before.',
73
                sprintf('<strong>%s</strong>', $user->name)
74
            ));
75
        } else {
76
            $user
77
                ->set('token', null)
78
                ->set('status', true);
79
80
            $result = $this->Users->save($user);
0 ignored issues
show
It seems like $user defined by $this->_getUser($id, $token) on line 62 can also be of type array; however, Community\Model\Table\UsersTable::save() does only seem to accept object<Cake\Datasource\EntityInterface>, 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...
81
            if ($result) {
82
                EventManager::trigger('Controller.Users.successActivate', $this, ['user' => $result]);
83
                $this->Flash->success(__d(
84
                    'community',
85
                    '«{0}», you profile has been activate successfully.',
86
                    sprintf('<strong>%s</strong>', $user->name)
87
                ));
88
            } else {
89
                $this->Flash->error(__d(
90
                    'community',
91
                    'An error has occurred. Please, try again.',
92
                    sprintf('<strong>%s</strong>', $user->name)
93
                ));
94
            }
95
        }
96
97
        return $this->redirect(['action' => 'login']);
98
    }
99
100
    /**
101
     * Login action.
102
     *
103
     * @return  \Cake\Http\Response|null
104
     *
105
     * @throws  \Aura\Intl\Exception
106
     */
107 View Code Duplication
    public function login()
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...
108
    {
109
        if ($this->request->is('post')) {
110
            $user = $this->Auth->identify();
111
            if ($user !== false) {
112
                $this->Auth->setUser($user);
0 ignored issues
show
It seems like $user defined by $this->Auth->identify() on line 110 can also be of type boolean; however, Cake\Controller\Component\AuthComponent::setUser() does only seem to accept array|object<ArrayAccess>, 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...
113
                return $this->redirect($this->Auth->redirectUrl());
114
            }
115
116
            $this->Flash->error(__d('community', 'Login or password is incorrect'));
117
        }
118
119
        $this->set('page_title', __d('community', 'Authorize profile'));
120
    }
121
122
    /**
123
     * Logout action.
124
     *
125
     * @return  \Cake\Http\Response|null
126
     */
127
    public function logout()
128
    {
129
        return $this->redirect($this->Auth->logout());
130
    }
131
132
    /**
133
     * Setup password action.
134
     *
135
     * @param   null|int $id        User id.
136
     * @param   null|string $token  User activation token.
137
     * @return  \Cake\Http\Response|null
138
     *
139
     * @throws  \Aura\Intl\Exception
140
     */
141
    public function setupPassword($id = null, $token = null)
142
    {
143
        $user = $this->_getUser($id, $token);
144
145 View Code Duplication
        if ($user === null) {
0 ignored issues
show
This code seems to be duplicated across 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...
146
            $this->Flash->error(__d('community', 'User was not found'));
147
            return $this->redirect(['action' => 'login']);
148
        }
149
150
        if ($this->request->is(['patch', 'post', 'put'])) {
151
            $entity = $this->Users->patchEntity($user, $this->request->getData());
0 ignored issues
show
It seems like $user defined by $this->_getUser($id, $token) on line 143 can also be of type array; however, Cake\ORM\Table::patchEntity() does only seem to accept object<Cake\Datasource\EntityInterface>, 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...
It seems like $this->request->getData() targeting Cake\Http\ServerRequest::getData() can also be of type null or string; however, Cake\ORM\Table::patchEntity() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
152
            if ($user->status) {
153
                $entity->set('token', null);
154
            }
155
156
            /** @var User $result */
157
            $result = $this->Users->save($user);
0 ignored issues
show
It seems like $user defined by $this->_getUser($id, $token) on line 143 can also be of type array; however, Community\Model\Table\UsersTable::save() does only seem to accept object<Cake\Datasource\EntityInterface>, 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...
158
            if ($result) {
159
                $this->Flash->success(__d(
160
                    'community',
161
                    '«{0}», You have successfully changed your password.',
162
                    sprintf('<strong>%s</strong>', $user->get('name'))
163
                ));
164
165
                if (!$user->status && $result->token !== null) {
166
                    return $this->redirect([
167
                        'action' => 'activate',
168
                        $user->id,
169
                        $user->token
170
                    ]);
171
                }
172
173
                return $this->redirect(['action' => 'login']);
174
            } else {
175
                $this->Flash->error(__d('community', 'An error has occurred. Please, try again.'));
176
            }
177
        }
178
179
        $this
180
            ->set('user', $user)
181
            ->set('page_title', __d('community', 'Setup new password'));
182
    }
183
184
    /**
185
     * Get user by id and activation token.
186
     *
187
     * @param   int $id         User id.
188
     * @param   string $token   User activation token.
189
     * @return  array|User|null
190
     */
191
    private function _getUser($id, $token)
192
    {
193
        return $this->Users->find()
194
            ->where([
195
                'id'    => $id,
196
                'token' => $token
197
            ])
198
            ->first();
199
    }
200
}
201