Issues (1844)

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/Response.php (8 issues)

1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp;
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Eric Juden <[email protected]>
19
 * @author       XOOPS Development Team
20
 */
21
22
if (!\defined('XHELP_CLASS_PATH')) {
23
    exit();
24
}
25
26
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php';
27
28
/**
29
 * Response class
30
 *
31
 * @author  Eric Juden <[email protected]>
32
 */
33
class Response extends \XoopsObject
34
{
35
    private $helper;
36
37
    /**
38
     * Response constructor.
39
     * @param int|array|null $id
40
     */
41
    public function __construct($id = null)
42
    {
43
        $this->initVar('id', \XOBJ_DTYPE_INT, null, false);
44
        $this->initVar('uid', \XOBJ_DTYPE_INT, null, false);
45
        $this->initVar('ticketid', \XOBJ_DTYPE_INT, null, false);
46
        $this->initVar('message', \XOBJ_DTYPE_TXTAREA, null, false, 1000000);
47
        $this->initVar('timeSpent', \XOBJ_DTYPE_INT, null, false);
48
        $this->initVar('updateTime', \XOBJ_DTYPE_INT, null, true);
49
        $this->initVar('userIP', \XOBJ_DTYPE_TXTBOX, null, true, 35);
50
        $this->initVar('private', \XOBJ_DTYPE_INT, null, false);
51
52
        $this->helper = Helper::getInstance();
53
        if (null !== $id) {
54
            if (\is_array($id)) {
55
                $this->assignVars($id);
56
            }
57
        } else {
58
            $this->setNew();
59
        }
60
    }
61
62
    /**
63
     * Formats the posted date as the XOOPS date formate
64
     *
65
     * @param string $format
66
     * @return string Formatted posted date
67
     */
68
    public function posted(string $format = 'l'): string
69
    {
70
        return \formatTimestamp($this->getVar('updateTime'), $format);
71
    }
72
73
    /**
74
     * @param string $post_field
75
     * @param null   $response
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $response is correct as it would always require null to be passed?
Loading history...
76
     * @param null   $allowed_mimetypes
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $allowed_mimetypes is correct as it would always require null to be passed?
Loading history...
77
     * @return array|false|object|string|void
78
     */
79
    public function storeUpload(string $post_field, $response = null, $allowed_mimetypes = null)
80
    {
81
        //global $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsModule;
82
        // require_once XHELP_CLASS_PATH . '/uploader.php';
83
        $config = Utility::getModuleConfig();
84
85
        $ticketid = $this->getVar('id');
86
87
        if (null === $allowed_mimetypes) {
0 ignored issues
show
The condition null === $allowed_mimetypes is always true.
Loading history...
88
            /** @var \XoopsModules\Xhelp\MimetypeHandler $mimetypeHandler */
89
            $mimetypeHandler   = $this->helper->getHandler('Mimetype');
90
            $allowed_mimetypes = $mimetypeHandler->checkMimeTypes($post_field);
91
            if (!$allowed_mimetypes) {
0 ignored issues
show
The condition $allowed_mimetypes is always false.
Loading history...
92
                return false;
93
            }
94
        }
95
96
        $maxfilesize   = $config['xhelp_uploadSize'];
97
        $maxfilewidth  = $config['xhelp_uploadWidth'];
98
        $maxfileheight = $config['xhelp_uploadHeight'];
99
        if (!\is_dir(XHELP_UPLOAD_PATH)) {
0 ignored issues
show
The constant XoopsModules\Xhelp\XHELP_UPLOAD_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
100
            if (!\mkdir($concurrentDirectory = XHELP_UPLOAD_PATH, 0757) && !\is_dir($concurrentDirectory)) {
101
                throw new \RuntimeException(\sprintf('Directory "%s" was not created', $concurrentDirectory));
102
            }
103
        }
104
105
        $uploader = new MediaUploader(XHELP_UPLOAD_PATH . '/', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
106
        if ($uploader->fetchMedia($post_field)) {
107
            if (null === $response) {
108
                $uploader->setTargetFileName($ticketid . '_' . $uploader->getMediaName());
109
            } else {
110
                $uploader->setTargetFileName($ticketid . '_' . $response . '_' . $uploader->getMediaName());
111
            }
112
            if ($uploader->upload()) {
113
                $fileHandler = $this->helper->getHandler('File');
114
                $file        = $fileHandler->create();
115
                $file->setVar('filename', $uploader->getSavedFileName());
116
                $file->setVar('ticketid', $ticketid);
117
                $file->setVar('mimetype', $allowed_mimetypes);
118
                $file->setVar('responseid', (null !== $response ? (int)$response : 0));
119
120
                if ($fileHandler->insert($file)) {
121
                    return $file;
122
                }
123
124
                return $uploader->getErrors();
125
            }
126
127
            return $uploader->getErrors();
128
        }
129
    }
130
131
    /**
132
     * @param string $post_field
133
     * @param array  $allowed_mimetypes
134
     * @param array  $errors
135
     * @return bool
136
     */
137
    public function checkUpload(string $post_field, array &$allowed_mimetypes, array &$errors): bool
138
    {
139
        //global $xoopsModuleConfig;
140
        // require_once XHELP_CLASS_PATH . '/uploader.php';
141
        $config        = Utility::getModuleConfig();
142
        $maxfilesize   = $config['xhelp_uploadSize'];
143
        $maxfilewidth  = $config['xhelp_uploadWidth'];
144
        $maxfileheight = $config['xhelp_uploadHeight'];
145
        $errors        = [];
146
147
        if (null === $allowed_mimetypes) {
0 ignored issues
show
The condition null === $allowed_mimetypes is always false.
Loading history...
148
            $mimetypeHandler   = $this->helper->getHandler('Mimetype');
149
            $allowed_mimetypes = $mimetypeHandler->checkMimeTypes($post_field);
150
            if (!$allowed_mimetypes) {
151
                $errors[] = \_XHELP_MESSAGE_WRONG_MIMETYPE;
152
153
                return false;
154
            }
155
        }
156
        $uploader = new MediaUploader(XHELP_UPLOAD_PATH . '/', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
0 ignored issues
show
The constant XoopsModules\Xhelp\XHELP_UPLOAD_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
157
158
        if ($uploader->fetchMedia($post_field)) {
159
            return true;
160
        }
161
162
        $errors = \array_merge($errors, $uploader->getErrors(false));
163
164
        return false;
165
    }
166
167
    /**
168
     * Get the ticket to which the response is attached
169
     * @return \XoopsObject|null The ticket ID
170
     */
171
    public function getTicket(): ?\XoopsObject
172
    {
173
        $ticketHandler = $this->helper->getHandler('Ticket');
174
175
        return $ticketHandler->get($this->getVar('ticketid'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ticketHandler->g...is->getVar('ticketid')) could return the type false which is incompatible with the type-hinted return XoopsObject|null. Consider adding an additional type-check to rule them out.
Loading history...
176
    }
177
}
178