Issues (340)

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.

include/functions.user.php (3 issues)

1
<?php declare(strict_types=1);
2
3
/**
4
 * Newbb module
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       XOOPS Project (https://xoops.org)
14
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @since           4.0
16
 * @author          Taiwen Jiang <[email protected]>
17
 */
18
19
use XoopsModules\Newbb\{
20
    Forum,
21
    Helper
22
};
23
24
/** @var Helper $helper */
25
/**
26
 * Function to a list of user names associated with their user IDs
27
 * @param mixed[]|int $uid
28
 * @param bool  $usereal
29
 * @param bool $linked
30
 * @return array
31
 */
32
function newbbGetUnameFromIds($uid, bool $usereal = false, bool $linked = false): array
33
{
34
    xoops_load('xoopsuserutility');
35
    $ids = \XoopsUserUtility::getUnameFromIds($uid, $usereal, $linked);
36
37
    return $ids;
38
}
39
40
/**
41
 * @param int  $uid
42
 * @param int  $usereal
43
 * @param bool $linked
44
 * @return string
45
 */
46
function newbbGetUnameFromId(int $uid, int $usereal = 0, bool $linked = false): string
47
{
48
    xoops_load('xoopsuserutility');
49
50
    return \XoopsUserUtility::getUnameFromId($uid, $usereal, $linked);
51
}
52
53
/**
54
 * Function to check if a user is an administrator of the module
55
 *
56
 * @param int|string|array|\XoopsUser $user
57
 * @param int                         $mid
58
 * @return bool
59
 */
60
function newbbIsAdministrator($user = -1, int $mid = 0): bool
61
{
62
    global $xoopsModule;
63
64
    if (is_numeric($user) && -1 === $user) {
65
        $user = $GLOBALS['xoopsUser'];
66
    }
67
    if (!is_object($user) && (int)$user < 1) {
68
        return false;
69
    }
70
    $uid = is_object($user) ? $user->getVar('uid') : (int)$user;
71
72
    if (!$mid) {
73
        if (is_object($xoopsModule) && 'newbb' === $xoopsModule->getVar('dirname', 'n')) {
74
            $mid = $xoopsModule->getVar('mid', 'n');
75
        } else {
76
            /** @var \XoopsModuleHandler $moduleHandler */
77
            $moduleHandler = xoops_getHandler('module');
78
            $newbb_module  = $moduleHandler->getByDirname('newbb');
79
            $mid           = $newbb_module->getVar('mid', 'n');
80
            unset($newbb_module);
81
        }
82
    }
83
84
    if (is_object($xoopsModule) && is_object($GLOBALS['xoopsUser']) && $mid == $xoopsModule->getVar('mid', 'n')
85
        && $uid == $GLOBALS['xoopsUser']->getVar('uid', 'n')) {
86
        return $GLOBALS['xoopsUserIsAdmin'];
87
    }
88
89
    /** @var \XoopsMemberHandler $memberHandler */
90
    $memberHandler = xoops_getHandler('member');
91
    $groups        = $memberHandler->getGroupsByUser($uid);
92
93
    /** @var \XoopsGroupPermHandler $grouppermHandler */
94
    $grouppermHandler = xoops_getHandler('groupperm');
95
96
    return $grouppermHandler->checkRight('module_admin', $mid, $groups);
97
}
98
99
/**
100
 * Function to check if a user is a moderator of a forum
101
 *
102
 * @param mixed $forum
103
 * @param int|array |string|\XoopsUser $user
104
 * @return bool
105
 */
106
function newbbIsModerator(&$forum, $user = -1): bool
107
{
108
    if (!is_object($forum)) {
109
        $forum_id = (int)$forum;
110
        if (0 === $forum_id) {
111
            return false;
112
        }
113
        $forumHandler = Helper::getInstance()->getHandler('Forum');
114
        $forum        = $forumHandler->get($forum_id);
115
    }
116
117
    if (is_numeric($user) && -1 == $user) {
118
        $user = $GLOBALS['xoopsUser'];
119
    }
120
    if (!is_object($user) && (int)$user < 1) {
121
        return false;
122
    }
123
    $uid = is_object($user) ? $user->getVar('uid', 'n') : (int)$user;
124
125
    return in_array($uid, $forum->getVar('forum_moderator'), true);
0 ignored issues
show
It seems like $forum->getVar('forum_moderator') can also be of type boolean and null and string; however, parameter $haystack of in_array() does only seem to accept array, 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

125
    return in_array($uid, /** @scrutinizer ignore-type */ $forum->getVar('forum_moderator'), true);
Loading history...
126
}
127
128
/**
129
 * Function to check if a user has moderation permission over a forum
130
 *
131
 * @param Forum|int $forum
132
 * @return bool
133
 */
134
function newbbIsAdmin($forum = 0): bool
135
{
136
    global $xoopsModule;
137
    static $_cachedModerators;
138
139
    if (empty($forum)) {
140
        return $GLOBALS['xoopsUserIsAdmin'];
141
    }
142
143
    if (!is_object($GLOBALS['xoopsUser'])) {
144
        return false;
145
    }
146
147
    if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $xoopsModule->getVar('dirname')) {
148
        return true;
149
    }
150
151
    $cache_id = is_object($forum) ? $forum->getVar('forum_id', 'n') : (int)$forum;
152
    if (!isset($_cachedModerators[$cache_id])) {
153
        if (!is_object($forum)) {
154
            $forumHandler = Helper::getInstance()->getHandler('Forum');
155
            $forum        = $forumHandler->get((int)$forum);
156
        }
157
        $_cachedModerators[$cache_id] = $forum->getVar('forum_moderator');
158
    }
159
160
    return in_array($GLOBALS['xoopsUser']->getVar('uid'), $_cachedModerators[$cache_id], true);
161
}
162
163
/* use hardcoded DB query to save queries */
164
/**
165
 * @param array $uid
166
 *
167
 * @return array
168
 *
169
 * @psalm-return list<mixed>
170
 */
171
function newbbIsModuleAdministrators(array $uid = []): array
172
{
173
    global $xoopsModule;
174
    $module_administrators = [];
175
176
    //    $xoopsMembershipHandler = xoops_getHandler('membership');
177
    //    $xoopsMembershipTable   = $xoopsMembershipHandler->table;
178
179
    /** @var \XoopsMembershipHandler $xoopsMembershipHandler */
180
    $xoopsMembershipHandler = xoops_getHandler('membership');
181
    $xoopsMembershipTable   = $xoopsMembershipHandler->table;
182
    /** @var \XoopsGroupPermHandler $grouppermHandler */
183
    $grouppermHandler = xoops_getHandler('groupperm');
184
    $xoopsGroupPermTable   = $grouppermHandler->table;
185
186
    if (!$uid) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $uid of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
187
        return $module_administrators;
188
    }
189
    $mid = $xoopsModule->getVar('mid');
190
191
    $sql = 'SELECT COUNT(l.groupid) AS count, l.uid FROM '
192
           . $xoopsMembershipTable
193
           . ' AS l'
194
           . ' LEFT JOIN '
195
           . $xoopsGroupPermTable
196
           . ' AS p ON p.gperm_groupid=l.groupid'
197
           . ' WHERE l.uid IN ('
198
           . implode(', ', array_map('\intval', $uid))
199
           . ')'
200
           . "    AND p.gperm_modid = '1' AND p.gperm_name = 'module_admin' AND p.gperm_itemid = '"
201
           . (int)$mid
202
           . "'"
203
           . ' GROUP BY l.uid';
204
205
    $result = $GLOBALS['xoopsDB']->query($sql);
206
    if ($GLOBALS['xoopsDB']->isResultSet($result)) {
207
        while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
208
            if (!empty($myrow['count'])) {
209
                $module_administrators[] = $myrow['uid'];
210
            }
211
        }
212
    }
213
214
    return $module_administrators;
215
}
216
217
/* use hardcoded DB query to save queries */
218
/**
219
 * @param array $uid
220
 * @param int   $mid
221
 * @return array
222
 */
223
function newbbIsForumModerators(array $uid = [], int $mid = 0): array
0 ignored issues
show
The parameter $mid is not used and could be removed. ( Ignorable by Annotation )

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

223
function newbbIsForumModerators(array $uid = [], /** @scrutinizer ignore-unused */ int $mid = 0): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
224
{
225
    $forum_moderators = [];
226
227
    if ($uid === []) {
228
        return $forum_moderators;
229
    }
230
231
    $sql    = 'SELECT forum_moderator FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_forums');
232
    $result = $GLOBALS['xoopsDB']->query($sql);
233
    if ($GLOBALS['xoopsDB']->isResultSet($result)) {
234
        while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
235
            if (empty($myrow['forum_moderator'])) {
236
                continue;
237
            }
238
            $forum_moderators = array_merge($forum_moderators, (array)unserialize($myrow['forum_moderator']));
239
        }
240
    }
241
242
    return array_unique($forum_moderators??[]);
243
}
244
//ENDIF;
245