Issues (134)

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/Utility.php (11 issues)

1
<?php
2
3
namespace XoopsModules\Xfguestbook;
4
5
use XoopsModules\Xfguestbook;
6
use XoopsModules\Xfguestbook\Common;
7
use XoopsModules\Xfguestbook\Constants;
8
9
/**
10
 * Class Utility
11
 */
12
class Utility extends Common\SysUtility
13
{
14
    //--------------- Custom module methods -----------------------------
15
16
    public static function upload()
17
    {
18
        global $xoopsModule, $preview_name, $msgstop;
19
        /** @var Helper $helper */
20
        $helper = Helper::getInstance();
21
22
        $created = \time();
23
        $ext     = \preg_replace("/^.+\.([^.]+)$/sU", '\\1', $_FILES['photo']['name']);
0 ignored issues
show
The assignment to $ext is dead and can be removed.
Loading history...
24
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
25
        $field = $_POST['xoops_upload_file'][0];
26
        if (!empty($field) || '' !== $field) {
27
            // Check if file uploaded
28
            if ('' === $_FILES[$field]['tmp_name'] || !\is_readable($_FILES[$field]['tmp_name'])) {
29
                $msgstop .= \sprintf(MD_XFGUESTBOOK_FILEERROR, $helper->getConfig('photo_maxsize'));
30
            } else {
31
                $photos_dir              = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
32
                $array_allowed_mimetypes = ['image/gif', 'image/pjpeg', 'image/jpeg', 'image/x-png'];
33
                $uploader                = new \XoopsMediaUploader($photos_dir, $array_allowed_mimetypes, $helper->getConfig('photo_maxsize'), $helper->getConfig('photo_maxwidth'), $helper->getConfig('photo_maxheight'));
34
                if ($uploader->fetchMedia($field) && $uploader->upload()) {
35
                    if (null !== $preview_name) {
36
                        @\unlink("$photos_dir/" . $preview_name);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

36
                        /** @scrutinizer ignore-unhandled */ @\unlink("$photos_dir/" . $preview_name);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
37
                    }
38
                    $tmp_name     = $uploader->getSavedFileName();
39
                    $ext          = \preg_replace("/^.+\.([^.]+)$/sU", '\\1', $tmp_name);
40
                    $preview_name = 'tmp_' . $created . '.' . $ext;
41
                    \rename("$photos_dir/$tmp_name", "$photos_dir/$preview_name");
42
                } else {
43
                    $msgstop .= $uploader->getErrors();
44
                }
45
            }
46
        }
47
    }
48
49
    /**
50
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
51
     * @param int  $limit
52
     * @param int  $start
53
     * @return array
54
     */
55
    public static function getCountry($criteria = null, $limit = 0, $start = 0)
56
    {
57
        global $xoopsDB, $action;
58
        $ret = [];
59
        $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country');
60
        if (null !== $criteria && '' !== $criteria) {
0 ignored issues
show
The condition null !== $criteria is always false.
Loading history...
61
            $sql .= ' WHERE ' . $criteria;
62
        }
63
        $sql    .= ' ORDER BY country_code ASC';
64
        $result = $xoopsDB->query($sql, $limit, $start);
65
        while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
66
            $ret[] = $myrow;
67
        }
68
69
        return $ret;
70
    }
71
72
    /**
73
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
74
     * @param int  $limit
75
     * @param int  $start
76
     * @return array
77
     */
78
    public static function getAllCountry($criteria = null, $limit = 0, $start = 0)
79
    {
80
        global $xoopsDB, $action;
81
        /** @var Helper $helper */
82
        $helper = Helper::getInstance();
83
84
        $ret = [];
85
        $sql = 'SELECT country_code, country_name FROM ' . $xoopsDB->prefix('xfguestbook_country');
86
        if (null !== $criteria && '' !== $criteria) {
0 ignored issues
show
The condition null !== $criteria is always false.
Loading history...
87
            $sql .= ' WHERE ' . $criteria;
88
        }
89
        $sql    .= ' ORDER BY country_code ASC';
90
        $result = $xoopsDB->query($sql, $limit, $start);
91
        while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
92
            //      $ret[$myrow['country_code']] = $myrow['country_name'];
93
            $ret[$helper->getConfig('flagdir') . '/' . $myrow['country_code']] = $myrow['country_name'];
94
        }
95
96
        return $ret;
97
    }
98
99
    /**
100
     * @param $user_id
101
     * @return bool
102
     */
103
    public static function get_user_data($user_id)
104
    {
105
        global $xoopsUser;
106
        /** @var Helper $helper */
107
        $helper = Helper::getInstance();
108
109
        if (!(int)$user_id) {
110
            return false;
111
        }
112
113
        $poster = new \XoopsUser($user_id);
114
        if ($poster->isActive()) {
115
            $xoopsUser ? $a_poster['poster'] = "<a href='../../userinfo.php?uid=$user_id'>" . $poster->uname() . '</a>' : $a_poster['poster'] = $poster->uname();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$a_poster was never initialized. Although not strictly required by PHP, it is generally a good practice to add $a_poster = array(); before regardless.
Loading history...
116
            if ($helper->getConfig('display_avatar')) {
117
                $rank = $poster->rank();
118
                $rank['title'] ? $a_poster['rank'] = $rank['title'] : $a_poster['rank'] = '';
119
                $rank['image'] ? $a_poster['rank_img'] = "<img src='" . XOOPS_URL . '/uploads/' . $rank['image'] . '\' alt=\'\'>' : $a_poster['rank_img'] = '';
120
                $poster->user_avatar() ? $a_poster['avatar'] = "<img src='" . XOOPS_URL . '/uploads/' . $poster->user_avatar() . '\' alt=\'\'>' : $a_poster['avatar'] = '';
121
            } else {
122
                $a_poster['rank']     = '';
123
                $a_poster['avatar']   = '';
124
                $a_poster['rank_img'] = '';
125
            }
126
127
            return $a_poster;
128
        }
129
130
        return false;
131
    }
132
133
    // Effacement fichiers temporaires
134
135
    /**
136
     * @param         $dir_path
137
     * @param string  $prefix
138
     * @return int
139
     */
140
    public static function clear_tmp_files($dir_path, $prefix = 'tmp_')
141
    {
142
        if (!($dir = @\opendir($dir_path))) {
143
            return 0;
144
        }
145
        $ret        = 0;
146
        $prefix_len = mb_strlen($prefix);
0 ignored issues
show
The assignment to $prefix_len is dead and can be removed.
Loading history...
147
        while (false !== ($file = \readdir($dir))) {
148
            //        if (strncmp($file, $prefix, $prefix_len) === 0) {
149
            if (0 === mb_strpos($file, $prefix)) {
150
                if (@\unlink("$dir_path/$file")) {
151
                    $ret++;
152
                }
153
            }
154
        }
155
        \closedir($dir);
156
157
        return $ret;
158
    }
159
160
    // IP bannies (modérés automatiquement)
161
162
    /**
163
     * @param null $all
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $all is correct as it would always require null to be passed?
Loading history...
164
     * @return array
165
     */
166
    public static function get_badips($all = null)
167
    {
168
        global $xoopsDB;
169
        $ret    = [];
170
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_badips');
171
        $result = $xoopsDB->query($sql);
172
        if ($all) {
0 ignored issues
show
$all is of type null, thus it always evaluated to false.
Loading history...
173
            while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
174
                $ret[] = $myrow;
175
            }
176
        } else {
177
            while (list($ip_id, $ip_value) = $xoopsDB->fetchRow($result)) {
178
                $ret[] = $ip_value;
179
            }
180
        }
181
182
        return $ret;
183
    }
184
185
    /**
186
     * @param $email
187
     * @return bool
188
     */
189
    public static function email_exist($email)
190
    {
191
        if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) {
192
            return false;
193
        }
194
195
        if (!\checkdnsrr(\array_pop(\explode('@', $email)), 'MX')) {
0 ignored issues
show
explode('@', $email) cannot be passed to array_pop() as the parameter $array expects a reference. ( Ignorable by Annotation )

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

195
        if (!\checkdnsrr(\array_pop(/** @scrutinizer ignore-type */ \explode('@', $email)), 'MX')) {
Loading history...
196
            return false;
197
        }
198
199
        return true;
200
    }
201
}
202