Issues (411)

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/DownloadHandler.php (3 issues)

Labels
1
<?php
2
3
namespace XoopsModules\Wfdownloads;
4
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
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * Wfdownloads module
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package         wfdownload
21
 * @since           3.23
22
 * @author          Xoops Development Team
23
 */
24
25
require_once \dirname(__DIR__) . '/include/common.php';
26
27
/**
28
 * Class DownloadHandler
29
 */
30
class DownloadHandler extends \XoopsPersistableObjectHandler
31
{
32
    /**
33
     * @access public
34
     */
35
    public $helper;
36
37
    /**
38
     * @param null|\XoopsDatabase $db
39
     */
40
    public function __construct(\XoopsDatabase $db = null)
41
    {
42
        parent::__construct($db, 'wfdownloads_downloads', Download::class, 'lid', 'title');
43
        /** @var \XoopsModules\Wfdownloads\Helper $this ->helper */
44
        $this->helper = Helper::getInstance();
0 ignored issues
show
The property helper does not seem to exist on XoopsModules\Wfdownloads\Helper.
Loading history...
45
    }
46
47
    /**
48
     * Get maximum published date from a criteria
49
     *
50
     * @param \CriteriaElement|null $criteria
51
     *
52
     * @return mixed
53
     */
54
    public function getMaxPublishdate(\CriteriaElement $criteria = null)
55
    {
56
        $field = '';
57
        $groupby = false;
58
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
59
            if ('' != $criteria->groupby) {
60
                $groupby = true;
61
                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
62
            }
63
        }
64
        $sql = 'SELECT ' . $field . 'MAX(published) FROM ' . $this->table;
65
        if (\is_object($criteria)) {
66
            $sql .= ' ' . $criteria->renderWhere();
67
            if ('' != $criteria->groupby) {
68
                $sql .= $criteria->getGroupby();
69
            }
70
        }
71
        $result = $this->db->query($sql);
72
        if (!$result) {
73
            return 0;
74
        }
75
        if (!$groupby) {
76
            [$count] = $this->db->fetchRow($result);
77
78
            return $count;
79
        }
80
        $ret = [];
81
        while (list($id, $count) = $this->db->fetchRow($result)) {
82
            $ret[$id] = $count;
83
        }
84
85
        return $ret;
86
    }
87
88
    /**
89
     * Get criteria for active downloads
90
     *
91
     * @return \CriteriaCompo
92
     */
93
    public function getActiveCriteria()
94
    {
95
        /** @var \XoopsGroupPermHandler $grouppermHandler */
96
        $grouppermHandler = \xoops_getHandler('groupperm');
97
98
        $criteria = new \CriteriaCompo(new \Criteria('offline', false));
0 ignored issues
show
false of type false is incompatible with the type string expected by parameter $value of Criteria::__construct(). ( Ignorable by Annotation )

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

98
        $criteria = new \CriteriaCompo(new \Criteria('offline', /** @scrutinizer ignore-type */ false));
Loading history...
99
        $criteria->add(new \Criteria('published', 0, '>'));
100
        $criteria->add(new \Criteria('published', \time(), '<='));
101
        $expiredCriteria = new \CriteriaCompo(new \Criteria('expired', 0));
102
        $expiredCriteria->add(new \Criteria('expired', \time(), '>='), 'OR');
103
        $criteria->add($expiredCriteria);
104
        // add criteria for categories that the user has permissions for
105
        $groups                   = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
106
        $allowedDownCategoriesIds = $grouppermHandler->getItemIds('WFDownCatPerm', $groups, $this->helper->getModule()->mid());
107
        $criteria->add(new \Criteria('cid', '(' . \implode(',', $allowedDownCategoriesIds) . ')', 'IN'));
108
109
        return $criteria;
110
    }
111
112
    /**
113
     * Get array of active downloads with optional additional criteria
114
     *
115
     * @param \CriteriaCompo|null $crit Additional criteria
116
     *
117
     * @return array
118
     */
119
    public function getActiveDownloads(\CriteriaCompo $crit = null)
120
    {
121
        if (\is_object($crit)) {
122
            $criteria = $crit;
123
        } else {
124
            $criteria = new \CriteriaCompo();
125
        }
126
        $active_crit = $this->getActiveCriteria();
127
        $criteria->add($active_crit);
128
129
        return $this->getObjects($criteria);
130
    }
131
132
    /**
133
     * Get count of active downloads
134
     *
135
     * @param \CriteriaElement|null $crit Additional criteria
136
     *
137
     * @return int /int
138
     */
139
    public function getActiveCount(\CriteriaElement $crit = null)
140
    {
141
        $criteria = $this->getActiveCriteria();
142
        if (\is_object($crit)) {
143
            $criteria->add($crit);
144
        }
145
146
        return $this->getCount($criteria);
147
    }
148
149
    /**
150
     * Increment hit counter for a download
151
     *
152
     * @param int $lid
153
     *
154
     * @return bool
155
     */
156
    public function incrementHits($lid)
157
    {
158
        $sql = 'UPDATE ' . $this->table . " SET hits=hits+1 WHERE lid='" . (int)$lid . "'";
159
160
        return $this->db->queryF($sql);
161
    }
162
163
    /**
164
     * @param \XoopsObject $download
165
     * @param bool         $force
166
     *
167
     * @return bool
168
     */
169
    public function delete(\XoopsObject $download, $force = false)
170
    {
171
        if (parent::delete($download, $force)) {
172
            $criteria = new \Criteria('lid', (int)$download->getVar('lid'));
173
            $this->helper->getHandler('Rating')->deleteAll($criteria);
174
            $this->helper->getHandler('Mirror')->deleteAll($criteria);
175
            $this->helper->getHandler('Review')->deleteAll($criteria);
176
            $this->helper->getHandler('Report')->deleteAll($criteria);
177
            // delete comments
178
            \xoops_comment_delete((int)$this->helper->getModule()->mid(), (int)$download->getVar('lid'));
179
180
            // Formulize module support (2006/05/04) jpc - start
181
            if (Utility::checkModule('formulize')) {
182
                if (\is_file(XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php') && $download->getVar('formulize_idreq') > 0) {
183
                    require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php';
184
                    //deleteFormEntries(array($download->getVar('formulize_idreq')));
185
                    $category = $this->helper->getHandler('Category')->get($download->getVar('cid'));
186
                    deleteFormEntries([$download->getVar('formulize_idreq')], $category->getVar('formulize_fid'));
0 ignored issues
show
The function deleteFormEntries was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

186
                    /** @scrutinizer ignore-call */ 
187
                    deleteFormEntries([$download->getVar('formulize_idreq')], $category->getVar('formulize_fid'));
Loading history...
187
                }
188
            }
189
190
            // Formulize module support (2006/05/04) jpc - end
191
            return true;
192
        }
193
194
        return false;
195
    }
196
}
197