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.

index.php (2 issues)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
/**
4
 * NewBB,  the forum module for XOOPS project
5
 *
6
 * @copyright      XOOPS Project (https://xoops.org)
7
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
8
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
9
 * @since          4.00
10
 */
11
12
use Xmf\Request;
13
use XoopsModules\Newbb\{
14
    CategoryHandler,
15
    Helper,
16
    ForumHandler,
17
    OnlineHandler,
18
    PostHandler,
19
    ReportHandler,
20
    StatsHandler,
21
    UserstatsHandler
22
};
23
24
/** @var Helper $helper */
25
/** @var OnlineHandler $onlineHandler */
26
/** @var ForumHandler $forumHandler */
27
/** @var UserstatsHandler $userstatsHandler */
28
require_once __DIR__ . '/header.php';
29
30
global $xoopsModule;
31
32
/* deal with marks */
33
if (Request::getInt('mark_read', 0)) {
34
    if (1 === Request::getInt('mark_read', 0)) { // marked as read
35
        $markvalue  = 1;
36
        $markresult = _MD_NEWBB_MARK_READ;
37
    } else { // marked as unread
38
        $markvalue  = 0;
39
        $markresult = _MD_NEWBB_MARK_UNREAD;
40
    }
41
    require_once __DIR__ . '/include/functions.read.php';
42
    newbbSetReadforum($markvalue);
43
    $url = XOOPS_URL . '/modules/newbb/index.php';
44
    redirect_header($url, 2, _MD_NEWBB_ALL_FORUM_MARKED . ' ' . $markresult);
45
}
46
47
$viewcat = Request::getInt('cat', 0, 'GET'); //TODO mb check if this is GET or POST?
48
/** @var CategoryHandler $categoryHandler */
49
$categoryHandler = Helper::getInstance()->getHandler('Category');
50
51
$categories = [];
52
if ($viewcat) {
53
    $categoryObject = $categoryHandler->get($viewcat);
54
    if ($categoryHandler->getPermission($categoryObject)) {
55
        $categories[$viewcat] = $categoryObject->getValues();
56
    }
57
    $forumIndexTitle = sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars((string)$GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES));
58
    $xoopsPageTitle   = $categoryObject->getVar('cat_title') . ' [' . $xoopsModule->getVar('name') . ']';
59
} else {
60
    $categories        = $categoryHandler->getByPermission('access', null, false);
61
    $forumIndexTitle = '';
62
    $xoopsPageTitle   = $xoopsModule->getVar('name');
63
}
64
65
if (0 === (is_countable($categories) ? count($categories) : 0)) {
66
    redirect_header(XOOPS_URL, 2, _MD_NEWBB_NORIGHTTOACCESS);
67
}
68
69
$xoopsOption['template_main']   = 'newbb_index.tpl';
70
$xoopsOption['xoops_pagetitle'] = $xoopsPageTitle;
71
// irmtfan remove and move to footer.php
72
//$xoopsOption['xoops_module_header'] = $xoops_module_header;
73
// irmtfan include header.php after defining $xoopsOption['template_main']
74
require_once $GLOBALS['xoops']->path('header.php');
75
require_once __DIR__ . '/include/functions.render.php';
76
/* rss feed */
77
// irmtfan new method
78
if (!empty($GLOBALS['xoopsModuleConfig']['rss_enable'])) {
79
    $xoopsTpl->assign(
80
        'xoops_module_header',
81
        '
82
    <link rel="alternate" type="application/xml+rss" title="' . $xoopsModule->getVar('name') . '" href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/rss.php" >
83
    ' . @$xoopsTpl->get_template_vars('xoops_module_header')
84
    );
85
}
86
$xoopsTpl->assign('xoops_pagetitle', $xoopsPageTitle);
87
// irmtfan remove and move to footer.php
88
//$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
89
$xoopsTpl->assign('forum_index_title', $forumIndexTitle);
90
//if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
91
if (!empty($GLOBALS['xoopsModuleConfig']['wol_enabled'])) {
92
    //    $onlineHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Online');
93
    $onlineHandler->init();
94
    $xoopsTpl->assign('online', $onlineHandler->showOnline());
95
}
96
$forumHandler = Helper::getInstance()->getHandler('Forum');
97
/** @var PostHandler $postHandler */
98
$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
99
100
/* Allowed forums */
101
$forums_allowed = $forumHandler->getIdsByPermission();
102
103
/* fetch top forums */
104
$forums_top = [];
105
106
if (!empty($forums_allowed)) {
107
    $crit_top = new \CriteriaCompo(new \Criteria('parent_forum', '0'));
108
    $crit_top->add(new \Criteria('cat_id', '(' . implode(', ', array_keys($categories)) . ')', 'IN'));
109
    $crit_top->add(new \Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN'));
110
    $forums_top = $forumHandler->getIds($crit_top);
111
}
112
113
/* fetch subforums if required to display */
114
if ('hidden' === $GLOBALS['xoopsModuleConfig']['subforum_display'] || 0 === (is_countable($forums_top) ? count($forums_top) : 0)) {
115
    $forums_sub = [];
116
} else {
117
    $crit_sub = new \CriteriaCompo(new \Criteria('parent_forum', '(' . implode(', ', $forums_top) . ')', 'IN'));
118
    $crit_sub->add(new \Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN'));
119
    $forums_sub = $forumHandler->getIds($crit_sub);
120
}
121
122
/* Fetch forum data */
123
$availableForums = array_merge($forums_top, $forums_sub);
124
$forumsArray     = [];
125
$newTopics        = 0;
126
$deleteTopics     = 0;
127
$newPosts         = 0;
128
$deletePosts      = 0;
129
if (0 !== count($availableForums)) {
130
    $crit_forum = new \Criteria('forum_id', '(' . implode(', ', $availableForums) . ')', 'IN');
131
    $crit_forum->setSort('cat_id ASC, parent_forum ASC, forum_order');
132
    $crit_forum->setOrder('ASC');
133
    $forums       = $forumHandler->getAll($crit_forum, null, false);
134
    $newTopics    = $forumHandler->getTopicCount($forums, 0, 'pending');
135
    $deleteTopics = $forumHandler->getTopicCount($forums, 0, 'deleted');
136
    $forumsArray = $forumHandler->display($forums, $GLOBALS['xoopsModuleConfig']['length_title_index'], $GLOBALS['xoopsModuleConfig']['count_subforum']);
137
    $crit         = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $availableForums) . ')', 'IN'));
138
    $crit->add(new \Criteria('approved', '-1'));
139
    $deletePosts = $postHandler->getCount($crit);
140
    $crit        = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $availableForums) . ')', 'IN'));
141
    $crit->add(new \Criteria('approved', '0'));
142
    $newPosts = $postHandler->getCount($crit);
143
}
144
145
if ($newTopics > 0) {
146
    $xoopsTpl->assign('wait_new_topic', $newTopics);
147
}
148
if ($deleteTopics > 0) {
149
    $xoopsTpl->assign('delete_topic', $deleteTopics);
150
}
151
if ($newPosts > 0) {
152
    $xoopsTpl->assign('wait_new_post', $newPosts);
153
}
154
if ($deletePosts > 0) {
155
    $xoopsTpl->assign('delete_post', $deletePosts);
156
}
157
158
/** @var ReportHandler $reportHandler */
159
$reportHandler = Helper::getInstance()->getHandler('Report');
160
$reported = $reportHandler->getCount(new \Criteria('report_result', '0'));
161
$xoopsTpl->assign('reported_count', $reported);
162
if ($reported > 0) {
163
    $xoopsTpl->assign('report_post', sprintf(_MD_NEWBB_SEEWAITREPORT, $reported));
164
}
165
166
$forumsByCat = null;
167
if ((is_countable($forumsArray) ? count($forumsArray) : 0) > 0) {
168
    foreach ($forumsArray[0] as $parent => $forum) {
169
        if (isset($forumsArray[$forum['forum_id']])) {
170
            $forum['subforum'] = $forumsArray[$forum['forum_id']];
171
        }
172
        $forumsByCat[$forum['forum_cid']][] = $forum;
173
    }
174
}
175
176
$category_array = [];
177
$toggles        = newbbGetCookie('G', true);
178
$iconHandler    = newbbGetIconHandler();
179
$category_icon  = [
180
    'expand'   => $iconHandler->getImageSource('minus'),
181
    'collapse' => $iconHandler->getImageSource('plus'),
182
];
183
184
foreach (array_keys($categories) as $id) {
185
    $forums = [];
186
    $onecat = $categories[$id];
187
188
    $cat_element_id = 'cat_' . $onecat['cat_id'];
189
    $expand         = !((is_countable($toggles) ? count($toggles) : 0) > 0) || !in_array($cat_element_id, $toggles, true);
0 ignored issues
show
It seems like $toggles can also be of type 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

189
    $expand         = !((is_countable($toggles) ? count($toggles) : 0) > 0) || !in_array($cat_element_id, /** @scrutinizer ignore-type */ $toggles, true);
Loading history...
It seems like $toggles can also be of type string; however, parameter $value of count() does only seem to accept Countable|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

189
    $expand         = !((is_countable($toggles) ? count(/** @scrutinizer ignore-type */ $toggles) : 0) > 0) || !in_array($cat_element_id, $toggles, true);
Loading history...
190
    // START irmtfan to improve newbbDisplayImage
191
    if ($expand) {
192
        $cat_display      = 'block';        //irmtfan move semicolon
193
        $cat_icon_display = 'minus';
194
        $cat_alt          = _MD_NEWBB_HIDE;
195
    } else {
196
        $cat_display      = 'none';        //irmtfan move semicolon
197
        $cat_icon_display = 'plus';
198
        $cat_alt          = _MD_NEWBB_SEE;
199
    }
200
    $cat_displayImage = newbbDisplayImage($cat_icon_display, $cat_alt);
201
202
    if (isset($forumsByCat[$onecat['cat_id']])) {
203
        $forums = $forumsByCat[$onecat['cat_id']];
204
    }
205
206
    $cat_sponsor = [];
207
    @[$url, $title] = array_map('\trim', explode(' ', (string) $onecat['cat_url'], 2));
208
    if ('' === $title) {
209
        $title = $url;
210
    }
211
    $title = htmlspecialchars((string)$title, ENT_QUOTES | ENT_HTML5);
212
    if ('' !== $url) {
213
        $cat_sponsor = ['title' => $title, 'link' => formatURL($url)];
214
    }
215
    //$cat_image = $onecat['cat_image'];
216
    $cat_image = '';
217
    $cat_image = $onecat['cat_image'];
218
    if ('' !== $cat_image && $cat_image) {
219
        $cat_image = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/assets/images/category/' . $cat_image;
220
    }
221
    $category_array[] = [
222
        'cat_id'           => $onecat['cat_id'],
223
        'cat_title'        => $myts->displayTarea($onecat['cat_title'], 1),
224
        'cat_image'        => $cat_image,
225
        'cat_sponsor'      => $cat_sponsor,
226
        'cat_description'  => $myts->displayTarea($onecat['cat_description'], 1),
227
        'cat_element_id'   => $cat_element_id,
228
        'cat_display'      => $cat_display,
229
        'cat_displayImage' => $cat_displayImage,
230
        'forums'           => $forums,
231
    ];
232
}
233
234
unset($categories, $forumsArray, $forumsByCat);
235
$xoopsTpl->assign_by_ref('category_icon', $category_icon);
236
$xoopsTpl->assign_by_ref('categories', $category_array);
237
$xoopsTpl->assign('notifyicon', $category_icon);
238
239
$xoopsTpl->assign(
240
    [
241
        'index_title' => sprintf(_MD_NEWBB_WELCOME, htmlspecialchars((string)$GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)),
242
        'index_desc'  => _MD_NEWBB_TOSTART,
243
    ]
244
);
245
246
/* display user stats */
247
if (!empty($GLOBALS['xoopsModuleConfig']['statistik_enabled'])) {
248
    $userstats = [];
249
    if (is_object($GLOBALS['xoopsUser'])) {
250
        //        $userstatsHandler         = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Userstats');
251
        $userstats_row            = $userstatsHandler->getStats($GLOBALS['xoopsUser']->getVar('uid'));
252
        $userstats['topics']      = sprintf(_MD_NEWBB_USER_TOPICS, (int)(@$userstats_row['user_topics']));
253
        $userstats['posts']       = sprintf(_MD_NEWBB_USER_POSTS, (int)(@$userstats_row['user_posts']));
254
        $userstats['digests']     = sprintf(_MD_NEWBB_USER_DIGESTS, (int)(@$userstats_row['user_digests']));
255
        $userstats['currenttime'] = sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 's')); // irmtfan should be removed because it is for anon users too
256
        $userstats['lastvisit']   = sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 's')); // irmtfan should be removed because it is for anon users too
257
        $userstats['lastpost']    = empty($userstats_row['user_lastpost']) ? _MD_NEWBB_USER_NOLASTPOST : sprintf(_MD_NEWBB_USER_LASTPOST, formatTimestamp($userstats_row['user_lastpost'], 's'));
258
    }
259
    $xoopsTpl->assign_by_ref('userstats', $userstats);
260
    // irmtfan add lastvisit smarty variable for all users
261
    $xoopsTpl->assign('lastvisit', sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 'l')));
262
    $xoopsTpl->assign('currenttime', sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 'm')));
263
}
264
265
/* display forum stats */
266
/** @var StatsHandler $statsHandler */
267
$statsHandler = Helper::getInstance()->getHandler('Stats');
268
$stats = $statsHandler->getStats(array_merge([0], $availableForums));
269
$xoopsTpl->assign_by_ref('stats', $stats);
270
$xoopsTpl->assign('subforum_display', $GLOBALS['xoopsModuleConfig']['subforum_display']);
271
$xoopsTpl->assign('mark_read', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=1');
272
$xoopsTpl->assign('mark_unread', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=2');
273
274
$xoopsTpl->assign('all_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=all');
275
$xoopsTpl->assign('post_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=all');
276
$xoopsTpl->assign('newpost_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=new');
277
$xoopsTpl->assign('digest_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=digest');
278
$xoopsTpl->assign('unreplied_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unreplied');
279
$xoopsTpl->assign('unread_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unread');
280
$xoopsTpl->assign('menumode', $menumode);
281
$xoopsTpl->assign('menumode_other', $menumode_other);
282
283
$isAdmin = $GLOBALS['xoopsUserIsAdmin'];
284
$xoopsTpl->assign('viewer_level', $isAdmin ? 2 : is_object($GLOBALS['xoopsUser']));
285
$mode = Request::getInt('mode', 0, 'GET');
286
$xoopsTpl->assign('mode', $mode);
287
288
$xoopsTpl->assign('viewcat', $viewcat);
289
$xoopsTpl->assign('version', $xoopsModule->getVar('version'));
290
291
/* To be removed */
292
if ($isAdmin) {
293
    $xoopsTpl->assign('forum_index_cpanel', ['link' => 'admin/index.php', 'name' => _MD_NEWBB_ADMINCP]);
294
}
295
296
if (1 == $GLOBALS['xoopsModuleConfig']['rss_enable']) {
297
    $xoopsTpl->assign('rss_enable', 1);
298
    $xoopsTpl->assign('rss_button', newbbDisplayImage('rss', 'RSS feed'));
299
}
300
$xoopsTpl->assign(
301
    [
302
        'img_forum_new' => newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS),
303
        'img_forum'     => newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS),
304
        'img_subforum'  => newbbDisplayImage('subforum'),
305
    ]
306
);
307
308
// irmtfan move to footer.php
309
require_once __DIR__ . '/footer.php';
310
require_once $GLOBALS['xoops']->path('footer.php');
311
//added missing php closing tag
312
?>
313
<script>
314
    //Added by BigKev73 to force the reloading of this page when the browser back button is used. Otherwise, the unread envelope status won't update
315
    if (!!window.performance && window.performance.navigation.type === 2) {
316
        //console.log('Reloading');
317
        window.location.reload();
318
    }
319
</script>
320