Issues (380)

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.

class/ModerateHandler.php (1 issue)

Severity
1
<?php
2
3
namespace XoopsModules\Newbb;
4
5
/**
6
 * NewBB 5.0x,  the forum module for XOOPS project
7
 *
8
 * @copyright      XOOPS Project (https://xoops.org)
9
 * @license        GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
10
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
11
 * @since          4.00
12
 * @package        module::newbb
13
 */
14
15
use Xmf\IPAddress;
16
17
 /**
18
 * Class ModerateHandler
19
 */
20
class ModerateHandler extends \XoopsPersistableObjectHandler
21
{
22
    /**
23
     * @param null|\XoopsDatabase $db
24
     */
25
    public function __construct(\XoopsDatabase $db = null)
26
    {
27
        parent::__construct($db, 'newbb_moderates', Moderate::class, 'mod_id', 'uid');
28
    }
29
30
    /**
31
     * Clear garbage
32
     *
33
     * Delete all moderation information that has expired
34
     *
35
     * @param int $expire Expiration time in UNIX, 0 for time()
36
     */
37
    public function clearGarbage($expire = 0)
38
    {
39
        $expire = \time() - (int)$expire;
40
        $sql    = \sprintf('DELETE FROM `%s` WHERE mod_end < %u', $this->db->prefix('newbb_moderates'), $expire);
41
        $this->db->queryF($sql);
42
    }
43
44
    /**
45
     * Check if a user is moderated, according to his uid and ip
46
     *
47
     *
48
     * @param int         $uid user id
49
     * @param string|bool $ip  user ip
50
     * @param int         $forum
51
     * @return bool true if IP is banned
52
     */
53
    public function verifyUser($uid = -1, $ip = '', $forum = 0)
54
    {
55
        \error_reporting(\E_ALL);
56
        // if user is admin do not suspend
57
        if (\newbbIsAdmin($forum)) {
58
            return true;
59
        }
60
61
        $uid = ($uid < 0) ? (\is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0) : (int)$uid;
62
63
        $criteria      = new \CriteriaCompo(new \Criteria('uid', (int)$uid));
64
        $forumCriteria = new \CriteriaCompo(new \Criteria('forum_id', 0), 'OR');
65
        if (!empty($forum)) {
66
            $forumCriteria->add(new \Criteria('forum_id', (int)$forum), 'OR');
67
        }
68
        $criteria->add($forumCriteria);
69
        $criteria->add(new \Criteria('mod_end', \time(), '>'));
70
71
        $matches = $this->getAll($criteria);
72
73
        if (0 === \count($matches)) {
74
            return true; // no matches
75
        }
76
77
        if (\count($matches) > 0 && $uid > 0) {
78
            return false; // user is banned
79
        }
80
        // verify possible matches against IP address
81
        $ip = empty($ip) ? IPAddress::fromRequest()->asReadable() : $ip;
82
83
        foreach ($matches as $modMatch) {
84
            $rawModIp = \trim($modMatch->getVar('ip', 'n'));
85
            if (empty($rawModIp)) {
86
                return false; // banned without IP
87
            }
88
            $parts   = \explode('/', $rawModIp);
89
            $modIp   = $parts[0];
90
            $checkIp = new IPAddress($modIp);
91
            if (false !== $checkIp->asReadable()) {
92
                $defaultMask = (6 === $checkIp->ipVersion()) ? 128 : 32;
93
                $netMask     = isset($parts[1]) ? (int)$parts[1] : $defaultMask;
94
                if ($checkIp->sameSubnet($ip, $netMask, $netMask)) {
95
                    return false; // IP is banned
96
                }
97
            }
98
        }
99
100
        return true;
101
    }
102
103
    /**
104
     * Get latest expiration for a user moderation
105
     *
106
     *
107
     * @param mixed $item user id or ip
108
     * @param bool  $isUid
109
     * @return int
110
     */
111
    public function getLatest($item, $isUid = true)
112
    {
113
        $ips = [];
114
        if ($isUid) {
115
            $criteria = 'uid =' . (int)$item;
116
        } else {
117
            $ip_segs = \explode('.', $item);
118
            $segs    = \min(\count($ip_segs), 4);
119
            for ($i = 1; $i <= $segs; ++$i) {
120
                $ips[] = $this->db->quoteString(\implode('.', \array_slice($ip_segs, 0, $i)));
121
            }
122
            $criteria = 'ip IN(' . \implode(',', $ips) . ')';
123
        }
124
        $sql = 'SELECT MAX(mod_end) AS expire FROM ' . $this->db->prefix('newbb_moderates') . ' WHERE ' . $criteria;
125
        if (!$result = $this->db->query($sql)) {
126
            return -1;
127
        }
128
        $row = $this->db->fetchArray($result);
129
130
        return $row['expire'];
131
    }
132
133
    /**
134
     * clean orphan items from database
135
     *
136
     * @param string $table_link
137
     * @param string $field_link
138
     * @param string $field_object
139
     * @return bool   true on success
140
     */
141
    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
142
    {
143
        $sql = 'DELETE FROM ' . $this->table . ' WHERE (forum_id >0 AND forum_id NOT IN ( SELECT DISTINCT forum_id FROM ' . $this->db->prefix('newbb_forums') . ') )';
144
        if (!$result = $this->db->queryF($sql)) {
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
145
            //xoops_error($this->db->error());
146
            return false;
147
        }
148
149
        return true;
150
    }
151
}
152