Issues (116)

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/RldHandler.php (6 issues)

1
<?php
2
3
namespace XoopsModules\Xooghost;
4
5
/**
6
 * Xooghost module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
use Xoops\Core\Database\Connection;
22
23
/**
24
 * Class XooghostRldHandler
25
 */
26
class RldHandler extends \XoopsPersistableObjectHandler
27
{
28
    public $db;
29
30
    /**
31
     * @param null|\Xoops\Core\Database\Connection $db
32
     */
33
    public function __construct(Connection $db = null)
34
    {
35
        $this->db = $db;
36
        parent::__construct($db, 'xooghost_rld', Rld::class, 'xooghost_rld_id', 'xooghost_rld_page');
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public static function getInstance()
43
    {
44
        static $instance;
45
        if (!isset($instance)) {
46
            $class = __CLASS__;
47
            $instance = new $class($db);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
48
        }
49
50
        return $instance;
51
    }
52
53
    /**
54
     * @param $page_id
55
     *
56
     * @return int
57
     */
58
    public function getVotes($page_id)
59
    {
60
        $criteria = new \CriteriaCompo();
61
        $criteria->add(new \Criteria('xooghost_rld_page', $page_id));
62
        $criteria->add(new \Criteria('xooghost_rld_rates', 0, '!='));
63
64
        return parent::getCount($criteria);
65
    }
66
67
    /**
68
     * @param $page_id
69
     *
70
     * @return int
71
     */
72
    public function getbyUser($page_id)
73
    {
74
        $xoops = \Xoops::getInstance();
75
        $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
76
        $ip = $xoops->getEnv('REMOTE_ADDR');
77
78
        $criteria = new \CriteriaCompo();
79
        $criteria->add(new \Criteria('xooghost_rld_page', $page_id));
80
81
        $criteria2 = new \CriteriaCompo();
82
        $criteria2->add(new \Criteria('xooghost_rld_uid', $uid), 'OR');
0 ignored issues
show
It seems like $uid can also be of type string[]; however, parameter $value of Criteria::__construct() does only seem to accept 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

82
        $criteria2->add(new \Criteria('xooghost_rld_uid', /** @scrutinizer ignore-type */ $uid), 'OR');
Loading history...
83
        $criteria2->add(new \Criteria('xooghost_rld_ip', $ip), 'OR');
84
        $criteria->add($criteria2, 'AND');
85
        $tmp = $this->getObjects($criteria, false, false);
86
        if (0 != count($tmp)) {
87
            return $tmp[0]['xooghost_rld_rates'];
88
        }
89
90
        return 0;
91
    }
92
93
    /**
94
     * @param $page_id
95
     * @param $like_dislike
96
     *
97
     * @return bool
98
     */
99
    public function setLikeDislike($page_id, $like_dislike)
100
    {
101
        $xoops = \Xoops::getInstance();
102
        $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
103
        $ip = $xoops->getEnv('REMOTE_ADDR');
104
        $like = (1 == $like_dislike) ? 1 : 0;
105
        $dislike = (0 == $like_dislike) ? 1 : 0;
106
107
        $criteria = new \CriteriaCompo();
108
        $criteria->add(new \Criteria('xooghost_rld_page', $page_id));
109
110
        $criteria2 = new \CriteriaCompo();
111
        $criteria2->add(new \Criteria('xooghost_rld_uid', $uid), 'OR');
0 ignored issues
show
It seems like $uid can also be of type string[]; however, parameter $value of Criteria::__construct() does only seem to accept 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

111
        $criteria2->add(new \Criteria('xooghost_rld_uid', /** @scrutinizer ignore-type */ $uid), 'OR');
Loading history...
112
        $criteria2->add(new \Criteria('xooghost_rld_ip', $ip), 'OR');
113
        $criteria->add($criteria2, 'AND');
114
        $tmp = $this->getObjects($criteria, false, false);
115
        if (0 == count($tmp)) {
116
            $rldObject = $this->create();
117
            $rldObject->setVar('xooghost_rld_page', $page_id);
118
            $rldObject->setVar('xooghost_rld_uid', $uid);
119
            $rldObject->setVar('xooghost_rld_time', time());
120
            $rldObject->setVar('xooghost_rld_ip', $ip);
121
            $rldObject->setVar('xooghost_rld_rates', 0);
122
            $rldObject->setVar('xooghost_rld_like', $like);
123
            $rldObject->setVar('xooghost_rld_dislike', $dislike);
124
            if ($this->insert($rldObject)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->insert($rldObject) of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
125
                return true;
126
            }
127
        }
128
129
        return false;
130
    }
131
132
    /**
133
     * @param $page_id
134
     * @param $vote
135
     *
136
     * @return array|bool
137
     */
138
    public function setRate($page_id, $vote)
139
    {
140
        $xoops = \Xoops::getInstance();
141
        $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
142
        $ip = $xoops->getEnv('REMOTE_ADDR');
143
144
        $criteria = new \CriteriaCompo();
145
        $criteria->add(new \Criteria('xooghost_rld_page', $page_id));
146
147
        $criteria2 = new \CriteriaCompo();
148
        $criteria2->add(new \Criteria('xooghost_rld_uid', $uid), 'OR');
0 ignored issues
show
It seems like $uid can also be of type string[]; however, parameter $value of Criteria::__construct() does only seem to accept 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

148
        $criteria2->add(new \Criteria('xooghost_rld_uid', /** @scrutinizer ignore-type */ $uid), 'OR');
Loading history...
149
        $criteria2->add(new \Criteria('xooghost_rld_ip', $ip), 'OR');
150
        $criteria->add($criteria2, 'AND');
151
        $tmp = $this->getObjects($criteria, false, false);
152
        if (0 == count($tmp)) {
153
            $rldObject = $this->create();
154
            $rldObject->setVar('xooghost_rld_page', $page_id);
155
            $rldObject->setVar('xooghost_rld_uid', $uid);
156
            $rldObject->setVar('xooghost_rld_time', time());
157
            $rldObject->setVar('xooghost_rld_ip', $ip);
158
            $rldObject->setVar('xooghost_rld_rates', $vote);
159
            $rldObject->setVar('xooghost_rld_like', 0);
160
            $rldObject->setVar('xooghost_rld_dislike', 0);
161
            if ($tmp = $this->insert($rldObject)) {
0 ignored issues
show
The assignment to $tmp is dead and can be removed.
Loading history...
162
                return $this->getAverage($page_id, $vote);
163
            }
164
        }
165
166
        return false;
167
    }
168
169
    /**
170
     * @param $page_id
171
     * @param $vote
172
     *
173
     * @return array
174
     */
175
    private function getAverage($page_id, $vote)
176
    {
177
        $criteria = new \CriteriaCompo();
178
        $criteria->add(new \Criteria('xooghost_rld_page', $page_id));
179
        $criteria->add(new \Criteria('xooghost_rld_rates', 0, '!='));
180
181
        $res = $this->getObjects($criteria, false, false);
182
        $rates = 0;
183
        $voters = 0;
184
        foreach ($res as $k => $v) {
185
            $rates += $v['xooghost_rld_rates'];
186
            ++$voters;
187
        }
188
189
        return ['voters' => $voters, 'average' => ($rates / $voters), 'vote' => $vote];
190
    }
191
}
192