Issues (36)

Security Analysis    no request data  

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/Common/VersionChecks.php (7 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Gbook\Common;
6
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
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
use XoopsModule;
18
19
20
21
/**
22
 * @copyright   XOOPS Project (https://xoops.org)
23
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
24
 * @author      mamba <[email protected]>
25
 */
26
trait VersionChecks
27
{
28
    /**
29
     * Verifies XOOPS version meets minimum requirements for this module
30
     * @static
31
     * @param \XoopsModule|null $module
32
     *
33
     * @param null|string       $requiredVer
34
     * @return bool true if meets requirements, false if not
35
     */
36
    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null): bool
37
    {
38
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
39
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
40
        if (null === $module) {
41
            $module = XoopsModule::getByDirname($moduleDirName);
42
        }
43
        \xoops_loadLanguage('admin', $moduleDirName);
44
        \xoops_loadLanguage('common', $moduleDirName);
45
46
        //check for minimum XOOPS version
47
        $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
48
        if (null === $requiredVer) {
49
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
0 ignored issues
show
Are you sure $module->getInfo('min_xoops') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

49
            $requiredVer = '' . /** @scrutinizer ignore-type */ $module->getInfo('min_xoops'); //making sure it's a string
Loading history...
50
        }
51
        $success = true;
52
53
        if (\version_compare($currentVer, $requiredVer, '<')) {
54
            $success = false;
55
            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
56
        }
57
58
        return $success;
59
    }
60
61
    /**
62
     * Verifies PHP version meets minimum requirements for this module
63
     * @static
64
     * @param \XoopsModule|bool|null $module
65
     *
66
     * @return bool true if meets requirements, false if not
67
     */
68
    public static function checkVerPhp(XoopsModule $module = null): bool
69
    {
70
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
71
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
72
        if (null === $module) {
73
            $module = XoopsModule::getByDirname($moduleDirName);
74
        }
75
        \xoops_loadLanguage('admin', $moduleDirName);
76
        \xoops_loadLanguage('common', $moduleDirName);
77
78
        // check for minimum PHP version
79
        $success = true;
80
81
        $verNum = \PHP_VERSION;
82
        $reqVer = &$module->getInfo('min_php');
83
84
        if (false !== $reqVer && '' !== $reqVer) {
85
            if (\version_compare($verNum, $reqVer, '<')) {
0 ignored issues
show
It seems like $reqVer can also be of type array; however, parameter $version2 of version_compare() 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

85
            if (\version_compare($verNum, /** @scrutinizer ignore-type */ $reqVer, '<')) {
Loading history...
86
                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
0 ignored issues
show
It seems like $reqVer can also be of type array; however, parameter $values of sprintf() does only seem to accept double|integer|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

86
                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), /** @scrutinizer ignore-type */ $reqVer, $verNum));
Loading history...
87
                $success = false;
88
            }
89
        }
90
91
        return $success;
92
    }
93
94
    /**
95
     *
96
     * compares current module version with latest GitHub release
97
     * @static
98
     * @param \Xmf\Module\Helper $helper
99
     * @param string|null        $source
100
     * @param string|null        $default
101
     *
102
     * @return string|array info about the latest module version, if newer
103
     */
104
105
    public static function checkVerModule($helper, $source = 'github', $default = 'master')
106
    {
107
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
108
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
109
        $update             = '';
110
        $repository         = 'XoopsModules25x/' . $moduleDirName;
111
        //        $repository         = 'XoopsModules25x/publisher'; //for testing only
112
        $ret             = '';
113
        $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
114
        if ('github' === $source) {
115
            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
116
                \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
117
                \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
118
                \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
119
                \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
120
                $curlReturn = \curl_exec($curlHandle);
121
                if (false === $curlReturn) {
122
                    \trigger_error(\curl_error($curlHandle));
123
                } elseif (false !== \strpos($curlReturn, 'Not Found')) {
0 ignored issues
show
It seems like $curlReturn can also be of type true; however, parameter $haystack of strpos() 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

123
                } elseif (false !== \strpos(/** @scrutinizer ignore-type */ $curlReturn, 'Not Found')) {
Loading history...
124
                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
125
                } else {
126
                    $file              = json_decode($curlReturn, false);
0 ignored issues
show
It seems like $curlReturn can also be of type true; however, parameter $json of json_decode() 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

126
                    $file              = json_decode(/** @scrutinizer ignore-type */ $curlReturn, false);
Loading history...
127
                    $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
128
                    $latestVersion     = $file[0]->tag_name;
129
                    $prerelease        = $file[0]->prerelease;
130
                    if ('master' !== $latestVersionLink) {
131
                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
132
                    }
133
                    //"PHP-standardized" version
134
                    $latestVersion = mb_strtolower($latestVersion);
135
                    if (false !== mb_strpos($latestVersion, 'final')) {
136
                        $latestVersion = \str_replace('_', '', mb_strtolower($latestVersion));
137
                        $latestVersion = \str_replace('final', '', mb_strtolower($latestVersion));
138
                    }
139
                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
0 ignored issues
show
Are you sure $helper->getModule()->getInfo('version') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

139
                    $moduleVersion = (/** @scrutinizer ignore-type */ $helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
Loading history...
Are you sure $helper->getModule()->getInfo('module_status') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

139
                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . /** @scrutinizer ignore-type */ $helper->getModule()->getInfo('module_status'));
Loading history...
140
                    //"PHP-standardized" version
141
                    $moduleVersion = \str_replace(' ', '', mb_strtolower($moduleVersion));
142
                    //                    $moduleVersion = '1.0'; //for testing only
143
                    //                    $moduleDirName = 'publisher'; //for testing only
144
                    if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
145
                        $ret   = [];
146
                        $ret[] = $update;
147
                        $ret[] = $latestVersionLink;
148
                    }
149
                }
150
                \curl_close($curlHandle);
151
            }
152
        }
153
        return $ret;
154
    }
155
}
156