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.

action.post.php (1 issue)

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
    Helper,
15
    Topic,
16
    TopicHandler,
17
    Forum,
18
    ForumHandler,
19
    Post,
20
    PostHandler,
21
    Tree
22
};
23
/** @var TopicHandler $topicHandler */
24
/** @var ForumHandler $forumHandler */
25
/** @var PostHandler $postHandler */
26
/** @var Post $postObject */
27
28
require_once __DIR__ . '/header.php';
29
30
$topic_id = Request::getInt('topic_id', 0, 'POST');
31
$post_id  = Request::getArray('post_id', Request::getArray('post_id', [], 'POST'), 'GET');
32
// Change by BigKev73, changed this code back to what this was before as with this following change, trying to permanently delete a deleted post reports no selection made.
33
//$post_id = Request::getInt('post_id', 0, 'GET');
34
//if (Request::hasVar('post_id', 'POST')) {
35
//    Request::getArray('post_id', $post_id, 'POST');
36
//}*/
37
38
//    !empty($_POST['post_id']) ? $_POST['post_id'] : $post_id;
39
40
$uid = Request::getInt('uid', 0, 'GET');
41
42
$op   = Request::getCmd('op', Request::getCmd('op', '', 'POST'), 'GET');
43
$op   = in_array($op, ['approve', 'delete', 'restore', 'split'], true) ? $op : '';
44
$mode = Request::getInt('mode', 1, 'GET');
45
46
if (0 === (is_countable($post_id) ? count($post_id) : 0) || ('' === $op)) {
47
    // irmtfan - issue with javascript:history.go(-1)
48
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, \_MD_NEWBB_NO_SELECTION);
49
}
50
///** @var PostHandler $postHandler */
51
//$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
52
///** @var TopicHandler $topicHandler */
53
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
54
///** @var NewbbForumHandler $forumHandler */
55
//$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum');
56
if (0 === $topic_id) {
57
    $forumObject = null;
58
} else {
59
    /** @var Topic $topicObject */
60
    $topicObject = $topicHandler->get($topic_id);
61
    $forum_id    = $topicObject->getVar('forum_id');
62
    $forumObject = $forumHandler->get($forum_id);
63
}
64
65
$isAdmin = false;
66
if (assert($forumObject instanceof Forum)) {
67
    $isAdmin = newbbIsAdmin($forumObject);
68
}
69
70
if (!$isAdmin) {
71
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
72
}
73
74
75
$post_update2 = null;
76
switch ($op) {
77
    case 'restore':
78
        $post_id = array_values($post_id);
79
        sort($post_id);
80
        $topics = [];
81
        $forums = [];
82
        foreach ($post_id as $post) {
83
            $postObject = $postHandler->get($post);
84
            assert($postObject instanceof Post);
85
            if ($postObject->getVar('topic_id') < 1) {
86
                continue;
87
            }
88
89
            $postHandler->approve($postObject, true);
90
            $topics[$postObject->getVar('topic_id')] = 1;
91
            $forums[$postObject->getVar('forum_id')] = 1;
92
            unset($postObject);
93
        }
94
        foreach (array_keys($topics) as $topic) {
95
            $topicHandler->synchronization($topic);
96
        }
97
        foreach (array_keys($forums) as $forum) {
98
            $forumHandler->synchronization($forum);
99
        }
100
        break;
101
    case 'approve':
102
        $post_id = array_values($post_id);
103
        sort($post_id);
104
        $topics      = [];
105
        $forums      = [];
106
        $criteria    = new \Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN');
107
        $postArray = $postHandler->getObjects($criteria, true);
108
        foreach ($post_id as $post) {
109
            /** @var Post $postObject */
110
            $postObject = $postArray[$post];
111
            assert($postObject instanceof Post);
112
            if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) {
113
                continue;
114
            }
115
            $postHandler->approve($postObject);
116
            $topics[$postObject->getVar('topic_id')] = $post;
117
            $forums[$postObject->getVar('forum_id')] = 1;
118
        }
119
        foreach (array_keys($topics) as $topic) {
120
            $topicHandler->synchronization($topic);
121
        }
122
        foreach (array_keys($forums) as $forum) {
123
            $forumHandler->synchronization($forum);
124
        }
125
126
        if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
127
            break;
128
        }
129
130
        $criteria_topic = new \Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN');
131
        $topic_list     = $topicHandler->getList($criteria_topic);
132
133
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
134
        $forum_list     = $forumHandler->getList($criteria_forum);
135
136
        require_once __DIR__ . '/include/notification.inc.php';
137
        /** @var \XoopsNotificationHandler $notificationHandler */
138
        $notificationHandler = xoops_getHandler('notification');
139
        foreach ($post_id as $post) {
140
            $tags = [];
141
            /** @var Post[] $postArray [$post] */
142
            $tags['THREAD_NAME'] = $topic_list[$postArray[$post]->getVar('topic_id')];
143
            $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postArray[$post]->getVar('topic_id') . '&amp;forum=' . $postArray[$post]->getVar('forum_id');
144
            $tags['FORUM_NAME']  = $forum_list[$postArray[$post]->getVar('forum_id')];
145
            $tags['FORUM_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $postArray[$post]->getVar('forum_id');
146
            $tags['POST_URL']    = $tags['THREAD_URL'] . '&topic_id=' . $postArray[$post]->getVar('topic_id') . '#forumpost' . $post;
147
            $notificationHandler->triggerEvent('thread', $postArray[$post]->getVar('topic_id'), 'new_post', $tags);
148
            $notificationHandler->triggerEvent('forum', $postArray[$post]->getVar('forum_id'), 'new_post', $tags);
149
            $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
150
            $tags['POST_CONTENT'] = $postArray[$post]->getVar('post_text');
151
            $tags['POST_NAME']    = $postArray[$post]->getVar('subject');
152
            $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
153
            $notificationHandler->triggerEvent('forum', $postArray[$post]->getVar('forum_id'), 'new_fullpost', $tags);
154
        }
155
        break;
156
    case 'delete':
157
        $post_id = array_values($post_id);
158
        rsort($post_id);
159
        $topics = [];
160
        $forums = [];
161
        foreach ($post_id as $post) {
162
            $postObject = $postHandler->get($post);
163
            assert($postObject instanceof Post);
164
            if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) {
165
                continue;
166
            }
167
            $topics[$postObject->getVar('topic_id')] = 1;
168
            $forums[$postObject->getVar('forum_id')] = 1;
169
            $postHandler->myDelete($postObject, true);
170
            unset($postObject);
171
        }
172
        foreach (array_keys($topics) as $topic) {
173
            $topicHandler->synchronization($topic);
174
        }
175
        foreach (array_keys($forums) as $forum) {
176
            $forumHandler->synchronization($forum);
177
        }
178
        break;
179
    case 'split':
180
        $postObject = $postHandler->get($post_id);
181
        assert($postObject instanceof Post);
182
        if ((is_array($post_id) && 0 === count($post_id)) || $postObject->isTopic()) {
183
            break;
184
        }
185
        $topic_id = (int)$postObject->getVar('topic_id');
186
187
        $newtopic = $topicHandler->create();
188
        $newtopic->setVar('topic_title', $postObject->getVar('subject'), true);
189
        $newtopic->setVar('topic_poster', $postObject->getVar('uid'), true);
190
        $newtopic->setVar('forum_id', $postObject->getVar('forum_id'), true);
191
        $newtopic->setVar('topic_time', $postObject->getVar('post_time'), true);
192
        $newtopic->setVar('poster_name', $postObject->getVar('poster_name'), true);
193
        $newtopic->setVar('approved', 1, true);
194
        $topicHandler->insert($newtopic, true);
195
        $new_topic_id = $newtopic->getVar('topic_id');
196
197
        $pid = $postObject->getVar('pid');
198
199
        $postObject->setVar('topic_id', $new_topic_id, true);
200
        $postObject->setVar('pid', 0, true);
201
        $postHandler->insert($postObject);
202
203
        /* split a single post */
204
        if (1 === $mode) {
205
            $criteria = new \CriteriaCompo(new \Criteria('topic_id', (string)$topic_id));
206
            $criteria->add(new \Criteria('pid', $post_id));
207
            $postHandler->updateAll('pid', $pid, $criteria, true);
208
            /* split a post and its children posts */
209
        } elseif (2 === $mode) {
210
            require_once $GLOBALS['xoops']->path('class/xoopstree.php');
211
            $mytree = new Tree($GLOBALS['xoopsDB']->prefix('newbb_posts'), 'post_id', 'pid');
212
            $posts  = $mytree->getAllChildId($post_id);
213
            if ((is_countable($posts) ? count($posts) : 0) > 0) {
214
                $criteria = new \Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN');
215
                $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true);
216
            }
217
            /* split a post and all posts coming after */
218
        } elseif (3 === $mode) {
219
            $criteria = new \CriteriaCompo(new \Criteria('topic_id', (string)$topic_id));
220
            $criteria->add(new \Criteria('post_id', $post_id, '>'));
221
            $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true);
222
223
            unset($criteria);
224
            $criteria = new \CriteriaCompo(new \Criteria('topic_id', $new_topic_id));
225
            $criteria->add(new \Criteria('post_id', (string)$post_id, '>'));
226
            $postHandler->identifierName = 'pid';
227
            $posts                       = $postHandler->getList($criteria);
228
229
            unset($criteria);
230
            $post_update = [];
231
            foreach ($posts as $postid => $pid) {
232
                //                if (!in_array($pid, array_keys($posts))) {
233
                if (!array_key_exists($pid, $posts)) {
234
                    $post_update[] = $pid;
235
                }
236
                if (!array_key_exists($pid, $posts)) {
237
                    $post_update2[] = $pid;
238
                }
239
            }
240
            if (count($post_update)) {
241
                $criteria = new \Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN');
242
                $postHandler->updateAll('pid', $post_id, $criteria, true);
243
            }
244
        }
245
246
        $forum_id = $postObject->getVar('forum_id');
247
        $topicHandler->synchronization($topic_id);
248
        $topicHandler->synchronization($new_topic_id);
249
        //        $sql    = sprintf('UPDATE "%s" SET forum_topics = forum_topics+1 WHERE forum_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id);
250
        $sql    = sprintf('UPDATE %s SET forum_topics = forum_topics+1 WHERE forum_id = %u', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id);
0 ignored issues
show
It seems like $forum_id can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, 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

250
        $sql    = sprintf('UPDATE %s SET forum_topics = forum_topics+1 WHERE forum_id = %u', $GLOBALS['xoopsDB']->prefix('newbb_forums'), /** @scrutinizer ignore-type */ $forum_id);
Loading history...
251
        $result = $GLOBALS['xoopsDB']->queryF($sql);
252
253
        break;
254
}
255
if (!empty($topic_id)) {
256
    redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id", 2, _MD_NEWBB_DBUPDATED);
257
} elseif (!empty($forum_id)) {
258
    redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum=$forum_id", 2, _MD_NEWBB_DBUPDATED);
259
} else {
260
    redirect_header(XOOPS_URL . "/modules/newbb/viewpost.php?uid=$uid", 2, _MD_NEWBB_DBUPDATED);
261
}
262
// irmtfan move to footer.php
263
require_once __DIR__ . '/footer.php';
264
require_once $GLOBALS['xoops']->path('footer.php');
265