Issues (432)

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.

admin/user.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
/**
4
 * Extended User Profile
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
14
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @since               2.3.0
16
 * @author              Jan Pedersen
17
 * @author              Taiwen Jiang <[email protected]>
18
 */
19
20
use Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
22
use XoopsModules\Suico\{
23
    Form\UserForm,
24
    Profile,
25
    ProfileHandler
26
};
27
28
require_once __DIR__ . '/admin_header.php';
29
xoops_cp_header();
30
$adminObject->addItemButton(_AM_SUICO_ADDUSER, 'user.php?op=new', 'add');
31
$adminObject->displayNavigation(basename(__FILE__));
32
$adminObject->displayButton('left');
33
$op = $_REQUEST['op'] ?? 'list';
34
if ('editordelete' === $op) {
35
    $op = isset($_REQUEST['delete']) ? 'delete' : 'edit';
36
}
37
/** @var \XoopsMemberHandler $memberHandler */
38
$memberHandler = xoops_getHandler('member');
39
switch ($op) {
40
    default:
41
    case 'list':
42
        require_once $GLOBALS['xoops']->path('/class/xoopsformloader.php');
43
        $form    = new \XoopsThemeForm(_AM_SUICO_EDITUSER, 'form', 'user.php');
44
        $lastUid = \Xmf\Request::getInt('lastuid', null, 'GET');
45
        $form->addElement(new \XoopsFormSelectUser(_AM_SUICO_SELECTUSER, 'id', false, $lastUid));
46
        $form->addElement(new \XoopsFormHidden('op', 'editordelete'));
47
        $button_tray = new \XoopsFormElementTray('');
48
        $button_tray->addElement(new \XoopsFormButton('', 'edit', _EDIT, 'submit'));
49
        $button_tray->addElement(new \XoopsFormButton('', 'delete', _DELETE, 'submit'));
50
        $form->addElement($button_tray);
51
        $form->display();
52
        break;
53
    case 'new':
54
        xoops_loadLanguage('main', $GLOBALS['xoopsModule']->getVar('dirname', 'n'));
55
        $obj = $memberHandler->createUser();
56
        $obj->setGroups([XOOPS_GROUP_USERS]);
57
        $form = new UserForm($obj);
58
        $form->display();
59
        break;
60
    case 'edit':
61
        xoops_loadLanguage('main', $GLOBALS['xoopsModule']->getVar('dirname', 'n'));
62
        $obj = $memberHandler->getUser($_REQUEST['id']);
63
        if (in_array(XOOPS_GROUP_ADMIN, $obj->getGroups(), true) && !in_array(XOOPS_GROUP_ADMIN, $GLOBALS['xoopsUser']->getGroups(), true)) {
64
            // If not webmaster trying to edit a webmaster - disallow
65
            redirect_header('user.php', 3, _US_NOEDITRIGHT);
66
        }
67
        $form = new UserForm($obj);
68
        $form->display();
69
        break;
70
    case 'save':
71
        xoops_loadLanguage('main', $GLOBALS['xoopsModule']->getVar('dirname', 'n'));
72
        if (!$GLOBALS['xoopsSecurity']->check()) {
73
            redirect_header('user.php', 3, _US_NOEDITRIGHT . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
74
            exit;
75
        }
76
        // Dynamic fields
77
        /** @var ProfileHandler $profileHandler */
78
        $profileHandler = $helper->getHandler('Profile');
79
        // Get fields
80
        $fields     = $profileHandler->loadFields();
81
        $userfields = $profileHandler->getUserVars();
82
        // Get ids of fields that can be edited
83
        /** @var \XoopsGroupPermHandler $grouppermHandler */
84
        $grouppermHandler = xoops_getHandler('groupperm');
85
        $editable_fields  = $grouppermHandler->getItemIds('profile_edit', $GLOBALS['xoopsUser']->getGroups(), $GLOBALS['xoopsModule']->getVar('mid'));
86
        $uid              = empty($_POST['uid']) ? 0 : (int)$_POST['uid'];
87
        if (!empty($uid)) {
88
            $user = $memberHandler->getUser($uid);
89
            /** @var Profile $profile */
90
            $profile = $profileHandler->get($uid);
91
            if (!is_object($profile)) {
92
                $profile = $profileHandler->create();
93
                $profile->setVar('profile_id', $uid);
94
            }
95
        } else {
96
            $user    = $memberHandler->createUser();
97
            $profile = $profileHandler->create();
98
            if (count($fields) > 0) {
99
                foreach (array_keys($fields) as $i) {
100
                    $fieldname = $fields[$i]->getVar('field_name');
101
                    if (in_array($fieldname, $userfields, true)) {
102
                        $default = $fields[$i]->getVar('field_default');
103
                        if ('' === $default || null === $default) {
104
                            continue;
105
                        }
106
                        $user->setVar($fieldname, $default);
107
                    }
108
                }
109
            }
110
            $user->setVar('user_regdate', time());
111
            $user->setVar('level', 1);
112
            $user->setVar('user_avatar', 'avatars/blank.gif');
113
        }
114
        $myts = \MyTextSanitizer::getInstance();
115
        $user->setVar('uname', $_POST['uname']);
116
        $user->setVar('email', trim($_POST['email']));
117
        if (isset($_POST['level']) && $user->getVar('level') != (int)$_POST['level']) {
118
            $user->setVar('level', (int)$_POST['level']);
119
        }
120
        $vpass    = null;
121
        $password = null;
122
        if (!empty($_POST['password'])) {
123
            $password = Request::getString('password', '', 'POST');
124
            $vpass    = Request::getString('vpass', '', 'POST');
125
            $user->setVar('pass', password_hash($password, PASSWORD_DEFAULT));
126
        } elseif ($user->isNew()) {
127
            $vpass    = '';
128
            $password = '';
129
        }
130
        xoops_load('xoopsuserutility');
131
        $stop   = XoopsUserUtility::validate($user, $password, $vpass);
132
        $errors = [];
133
        if ('' != $stop) {
134
            $errors[] = $stop;
135
        }
136
        foreach (array_keys($fields) as $i) {
137
            $fieldname = $fields[$i]->getVar('field_name');
138
            if (in_array($fields[$i]->getVar('field_id'), $editable_fields, true) && isset($_REQUEST[$fieldname])) {
139
                if (in_array($fieldname, $userfields, true)) {
140
                    $value = $fields[$i]->getValueForSave($_REQUEST[$fieldname], $user->getVar($fieldname, 'n'));
141
                    $user->setVar($fieldname, $value);
142
                } else {
143
                    $value = $fields[$i]->getValueForSave(($_REQUEST[$fieldname] ?? ''), $profile->getVar($fieldname, 'n'));
144
                    $profile->setVar($fieldname, $value);
145
                }
146
            }
147
        }
148
        $new_groups = $_POST['groups'] ?? [];
149
        if (0 == count($errors)) {
150
            if ($memberHandler->insertUser($user)) {
151
                $profile->setVar('profile_id', $user->getVar('uid'));
152
                $profileHandler->insert($profile);
153
                require_once $GLOBALS['xoops']->path('/modules/system/constants.php');
154
                if ($grouppermHandler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $GLOBALS['xoopsUser']->getGroups(), 1)) {
155
                    //Update group memberships
156
                    $cur_groups     = $user->getGroups();
157
                    $added_groups   = array_diff($new_groups, $cur_groups);
158
                    $removed_groups = array_diff($cur_groups, $new_groups);
159
                    if (count($added_groups) > 0) {
160
                        foreach ($added_groups as $groupid) {
161
                            $memberHandler->addUserToGroup($groupid, $user->getVar('uid'));
162
                        }
163
                    }
164
                    if (count($removed_groups) > 0) {
165
                        foreach ($removed_groups as $groupid) {
166
                            $memberHandler->removeUsersFromGroup($groupid, [$user->getVar('uid')]);
167
                        }
168
                    }
169
                }
170
                XoopsLoad::load('XoopsCache');
171
                $queryCache = XoopsCache::delete('formselectuser');
172
                if ($user->isNew()) {
173
                    redirect_header('user.php?lastuid=' . $user->getVar('uid'), 2, _AM_SUICO_USERCREATED, false);
174
                } else {
175
                    redirect_header('user.php?lastuid=' . $user->getVar('uid'), 2, _US_PROFUPDATED, false);
176
                }
177
            }
178
        } else {
179
            foreach ($errors as $err) {
180
                $user->setErrors($err);
181
            }
182
        }
183
        $user->setGroups($new_groups);
184
        echo $user->getHtmlErrors();
185
        $form = new UserForm($user, $profile);
186
        $form->display();
187
        break;
188
    case 'delete':
189
        if ($_REQUEST['id'] == $GLOBALS['xoopsUser']->getVar('uid')) {
190
            redirect_header('user.php', 2, _AM_SUICO_CANNOTDELETESELF);
191
        }
192
        $obj    = $memberHandler->getUser($_REQUEST['id']);
193
        $groups = $obj->getGroups();
194
        if (in_array(XOOPS_GROUP_ADMIN, $groups, true)) {
195
            redirect_header('user.php', 3, _AM_SUICO_CANNOTDELETEADMIN, false);
196
        }
197
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
198
            if (!$GLOBALS['xoopsSecurity']->check()) {
199
                redirect_header('user.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()), false);
200
            }
201
            $profileHandler = $helper->getHandler('Profile');
202
            $profile        = $profileHandler->get($obj->getVar('uid'));
203
            if (!$profile || $profile->isNew() || $profileHandler->delete($profile)) {
204
                if ($memberHandler->deleteUser($obj)) {
205
                    redirect_header('user.php', 3, sprintf(_AM_SUICO_DELETEDSUCCESS, $obj->getVar('uname') . ' (' . $obj->getVar('email') . ')'), false);
206
                } else {
207
                    echo $obj->getHtmlErrors();
208
                }
209
            } else {
210
                echo $profile->getHtmlErrors();
211
            }
212
        } else {
213
            xoops_confirm(
214
                [
215
                    'ok' => 1,
216
                    'id' => $_REQUEST['id'],
217
                    'op' => 'delete',
218
                ],
219
                $_SERVER['REQUEST_URI'],
220
                sprintf(_AM_SUICO_RUSUREDEL, $obj->getVar('uname') . ' (' . $obj->getVar('email') . ')')
221
            );
222
        }
223
        break;
224
}
225
require_once __DIR__ . '/admin_footer.php';
226
//xoops_cp_footer();
227