Issues (371)

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 (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll;
4
5
/**
6
 * Class Utility
7
 */
8
class Utility extends Common\SysUtility
9
{
10
    //--------------- Custom module methods -----------------------------
11
    /**
12
     * gets the name of the host located at a specific ip address
13
     * @param string $ipAddr the ip address of the host
14
     * @return string host name
15
     */
16
    public static function getHostByAddrWithCache(string &$ipAddr): string
17
    {
18
        static $ipArray = [];
19
        $retVal  = &$ipAddr;
20
        $options = ['flags' => \FILTER_FLAG_NO_PRIV_RANGE, \FILTER_FLAG_NO_RES_RANGE];
21
        if (\filter_var($ipAddr, \FILTER_VALIDATE_IP, $options)) {
22
            if (\array_key_exists($ipAddr, $ipArray)) {
23
                $retVal = $ipArray[$ipAddr];
24
            } else {
25
                $hostAddr = \gethostbyaddr($ipAddr);
26
                if ($hostAddr === $ipAddr) {
27
                    $retVal = &$ipAddr;
28
                } else {
29
                    $ipArray[$ipAddr] = \htmlspecialchars($hostAddr, \ENT_QUOTES | \ENT_HTML5);
30
                    $retVal           = $ipArray[$ipAddr];
31
                }
32
            }
33
        }
34
35
        return $retVal;
36
    }
37
38
    /**
39
     * Returns the global comment mode for this module
40
     * @static
41
     */
42
    public static function commentMode()
43
    {
44
        static $mConfig;
45
        if (!isset($mConfig)) {
46
            $mHandler = \xoops_getHandler('module');
47
            $mod      = $mHandler->getByDirname('xoopspoll');
0 ignored issues
show
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

47
            /** @scrutinizer ignore-call */ 
48
            $mod      = $mHandler->getByDirname('xoopspoll');
Loading history...
48
            /** @var \XoopsConfigHandler $cHandler */
49
            $cHandler = \xoops_getHandler('config');
50
            $mConfig  = &$cHandler->getConfigsByCat(0, $mod->getVar('mid'));
51
        }
52
53
        return $mConfig['com_rule'];
54
    }
55
56
    /**
57
     * Creates a visibility array from module default values
58
     * @return array visibility options available for a poll
59
     */
60
    public static function getVisibilityArray(): array
61
    {
62
        /**
63
         * {@internal Do NOT add/delete from $visOptions after the module has been installed}
64
         */
65
        static $visOptions = [];
66
        if (empty($visOptions)) {
67
            \xoops_loadLanguage('main', 'xoopspoll');
68
            $visOptions = [
69
                Constants::HIDE_NEVER  => \_MD_XOOPSPOLL_HIDE_NEVER,
70
                Constants::HIDE_END    => \_MD_XOOPSPOLL_HIDE_END,
71
                Constants::HIDE_VOTED  => \_MD_XOOPSPOLL_HIDE_VOTED,
72
                Constants::HIDE_ALWAYS => \_MD_XOOPSPOLL_HIDE_ALWAYS,
73
            ];
74
        }
75
76
        return $visOptions;
77
    }
78
79
    /**
80
     * Retrieves vote cookie from client system
81
     * The cookie name is based on the module directory. If module is
82
     * installed in default location then cookie name is 'voted_polls'
83
     * for backward compatibility. Otherwise , cookie is named
84
     * '<dirname>_voted_polls' to allow for module to be cloned using
85
     * smartClone module.
86
     * @param string $cookieBaseName
87
     * @return array  contains cookie for polls, empty array if not found
88
     */
89
    public static function getVoteCookie(string $cookieBaseName = 'voted_polls'): array
90
    {
91
        $pollDir = \basename(\dirname(__DIR__));
92
        if ('xoopspoll' === $pollDir) {
93
            $pollCookie = !empty($_COOKIE[$cookieBaseName]) ? $_COOKIE[$cookieBaseName] : [];
94
        } else {
95
            $pollCookie = !empty($_COOKIE["{$pollDir}_{$cookieBaseName}"]) ? $_COOKIE["{$pollDir}_{$cookieBaseName}"] : [];
96
        }
97
98
        return $pollCookie;
99
    }
100
101
    /**
102
     * Sets vote cookie on client system
103
     * The cookie name is based on the module directory. If module is
104
     * installed in default location then cookie name is 'voted_polls'
105
     * for backward compatibility. Otherwise , cookie is named
106
     * '<dirname>_voted_polls' to allow for module to be cloned using
107
     * smartClone module.
108
     * @param bool|int|string $index          array index to set in cookie
109
     * @param string          $value          data to store in cookie
110
     * @param int             $expires        time when cookie expires
111
     * @param string          $cookieBaseName name of cookie (without directory prefix)
112
     * @return bool         success in setting cookie
113
     */
114
    public static function setVoteCookie($index, string $value, int $expires = 0, string $cookieBaseName = 'voted_polls'): bool
115
    {
116
        $pollDir = \basename(\dirname(__DIR__));
117
        $success = false;
118
        // do a little sanity check on $index and $cookieBaseName
119
        if (!\is_bool($index) && !empty($cookieBaseName)) {
120
            if ('xoopspoll' === $pollDir) {
121
                $cookieName = $cookieBaseName;
122
            } else {
123
                $cookieName = $pollDir . '_' . $cookieBaseName;
124
            }
125
            $iVal = (string)$index;
126
            if (!empty($iVal)) {
127
                $success = setcookie($cookieName[$index], $value, (int)$expires);
128
                if ($success) {
129
                    $clientCookie = self::getVoteCookie();
130
                    if (!\array_key_exists($index, $clientCookie) || $clientCookie[$index] !== $value) {
131
                        $success = false;
132
                    }
133
                }
134
            } else {  //clear the cookie
135
                $success = setcookie($cookieName, '', (int)$expires);
136
                if ($success) {
137
                    $clientCookie = self::getVoteCookie();
138
                    if (!empty($clientCookie)) {
139
                        $success = false;
140
                    }
141
                }
142
            }
143
        }
144
145
        return $success;
146
    }
147
148
    /**
149
     * Sets vote cookie on client system
150
     * The cookie name is based on the module directory. If module is
151
     * installed in default location then cookie name is 'voted_polls'
152
     * for backward compatibility. Otherwise , cookie is named
153
     * '<dirname>_voted_polls' to allow for module to be cloned using
154
     * smartClone module.
155
     * @param \XoopsDatabase|null $db
156
     * @param  string $tablename
157
     * @return bool success in setting cookie
158
     * @internal param int|string $index array index to set in cookie
159
     * @internal param unknown_type $value data to store in cookie
160
     * @internal param int $expires time when cookie expires
161
     * @internal param string $cookieBaseName name of cookie (without directory prefix)
162
     */
163
    public static function dbTableExists(\XoopsDatabase $db, string $tablename): bool
164
    {
165
        $tablename = \addslashes($tablename);
166
        $mytable   = $db->prefix((string)$tablename);
167
        $result    = $db->queryF("SHOW TABLES LIKE '{$mytable}'");
168
        $found     = $db->getRowsNum($result);
169
170
        return !empty($found);
171
    }
172
}
173