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.

testdata/index.php (6 issues)

1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 * This program is distributed in the hope that it will be useful,
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
 *
10
 * @copyright       XOOPS Project (https://xoops.org)
11
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
12
 * @package
13
 * @since           2.5.9
14
 * @author          Michael Beck (aka Mamba)
15
 */
16
17
use Xmf\Database\TableLoad;
18
use \Xmf\Request;
19
use XoopsModules\Xfguestbook\{
20
    Helper,
21
    Common,
22
    Utility
23
};
24
use Xmf\Yaml;
25
26
require_once dirname(__DIR__, 3) . '/include/cp_header.php';
27
require dirname(__DIR__) . '/preloads/autoloader.php';
28
29
$op = Request::getCmd('op', '');
30
31
$moduleDirName      = basename(dirname(__DIR__));
32
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
33
34
$helper = Helper::getInstance();
35
// Load language files
36
$helper->loadLanguage('common');
37
38
switch ($op) {
39
    case 'load':
40
        if (Request::hasVar('ok', 'REQUEST') && 1 === Request::getInt('ok', 0)) {
41
            if (!$GLOBALS['xoopsSecurity']->check()) {
42
                redirect_header($helper->url('admin/index.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
43
            }
44
            loadSampleData();
45
        } else {
46
            xoops_cp_header();
47
            xoops_confirm(['ok' => 1, 'op' => 'load'], 'index.php', sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA_OK')), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true);
48
            xoops_cp_footer();
49
        }
50
        break;
51
    case 'save':
52
        saveSampleData();
53
        break;
54
}
55
56
// XMF TableLoad for SAMPLE data
57
58
function loadSampleData()
59
{
60
    global $xoopsConfig;
61
    $moduleDirName      = basename(dirname(__DIR__));
62
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
63
64
    $utility      = new Utility();
65
    $configurator = new Common\Configurator();
66
67
    $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables');
68
69
    $language = 'english/';
70
    if (is_dir(__DIR__ . '/' . $xoopsConfig['language'])) {
71
        $language = $xoopsConfig['language'] . '/';
72
    }
73
74
    // load module tables
75
    foreach ($tables as $table) {
76
        $tabledata = Yaml::readWrapped($language . $table . '.yml');
77
        TableLoad::truncateTable($table);
78
        TableLoad::loadTableFromArray($table, $tabledata);
79
    }
80
81
    // load permissions
82
    $table     = 'group_permission';
83
    $tabledata = Yaml::readWrapped($language . $table . '.yml');
84
    $mid       = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid');
85
    loadTableFromArrayWithReplace($table, $tabledata, 'gperm_modid', $mid);
86
87
    //  ---  COPY test folder files ---------------
88
    if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) {
89
        //        $file =  dirname(__DIR__) . '/testdata/images/';
90
        foreach (array_keys($configurator->copyTestFolders) as $i) {
91
            $src  = $configurator->copyTestFolders[$i][0];
92
            $dest = $configurator->copyTestFolders[$i][1];
93
            $utility::rcopy($src, $dest);
94
        }
95
    }
96
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
97
}
98
99
function saveSampleData()
100
{
101
    global $xoopsConfig;
102
    $moduleDirName      = basename(dirname(__DIR__));
103
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
104
105
    $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables');
106
107
    $languageFolder = __DIR__ . '/' . $xoopsConfig['language'];
108
    if (!file_exists($languageFolder . '/')) {
109
        Utility::createFolder($languageFolder . '/');
110
    }
111
    $exportFolder = $languageFolder . '/Exports-' . date('Y-m-d-H-i-s') . '/';
112
    Utility::createFolder($exportFolder);
113
114
    // save module tables
115
    foreach ($tables as $table) {
116
        TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml');
117
    }
118
119
    // save permissions
120
    $criteria = new \CriteriaCompo();
121
    $criteria->add(new \Criteria('gperm_modid', \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid')));
0 ignored issues
show
It seems like Xmf\Module\Helper::getHe...Module()->getVar('mid') can also be of type array and array; however, parameter $value of Criteria::__construct() 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

121
    $criteria->add(new \Criteria('gperm_modid', /** @scrutinizer ignore-type */ \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid')));
Loading history...
122
    $skipColumns[] = 'gperm_id';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$skipColumns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skipColumns = array(); before regardless.
Loading history...
123
    TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns);
124
    unset($criteria);
125
126
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
127
}
128
129
function exportSchema()
130
{
131
    $moduleDirName      = basename(dirname(__DIR__));
132
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
0 ignored issues
show
The assignment to $moduleDirNameUpper is dead and can be removed.
Loading history...
133
134
    try {
135
        // TODO set exportSchema
136
        //        $migrate = new Migrate($moduleDirName);
137
        //        $migrate->saveCurrentSchema();
138
        //
139
        //        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS'));
140
    } catch (\Throwable $e) {
0 ignored issues
show
catch (\Throwable $e) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
141
        exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR'));
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
142
    }
143
}
144
145
/**
146
 * loadTableFromArrayWithReplace
147
 *
148
 * @param string $table  value with should be used insead of original value of $search
149
 *
150
 * @param array  $data   array of rows to insert
151
 *                       Each element of the outer array represents a single table row.
152
 *                       Each row is an associative array in 'column' => 'value' format.
153
 * @param string $search name of column for which the value should be replaced
154
 * @param        $replace
155
 * @return int number of rows inserted
156
 */
157
function loadTableFromArrayWithReplace($table, $data, $search, $replace)
158
{
159
    /** @var \XoopsMySQLDatabase $db */
160
    $db = \XoopsDatabaseFactory::getDatabaseConnection();
161
162
    $prefixedTable = $db->prefix($table);
163
    $count         = 0;
164
165
    $sql = 'DELETE FROM ' . $prefixedTable . ' WHERE `' . $search . '`=' . $db->quote($replace);
166
167
    $result = $db->queryF($sql);
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
168
169
    foreach ($data as $row) {
170
        $insertInto  = 'INSERT INTO ' . $prefixedTable . ' (';
171
        $valueClause = ' VALUES (';
172
        $first       = true;
173
        foreach ($row as $column => $value) {
174
            if ($first) {
175
                $first = false;
176
            } else {
177
                $insertInto  .= ', ';
178
                $valueClause .= ', ';
179
            }
180
181
            $insertInto .= $column;
182
            if ($search === $column) {
183
                $valueClause .= $db->quote($replace);
184
            } else {
185
                $valueClause .= $db->quote($value);
186
            }
187
        }
188
189
        $sql = $insertInto . ') ' . $valueClause . ')';
190
191
        $result = $db->queryF($sql);
192
        if (false !== $result) {
193
            ++$count;
194
        }
195
    }
196
197
    return $count;
198
}
199