Issues (20)

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

1
<?php
2
3
namespace XoopsModules\Xoositemap;
4
5
/**
6
 * Xoopreferences : Preferences Manager
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
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xoositemap
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
21
 */
22
class Preferences
23
{
24
    public $config = [];
25
    public $basicConfig = [];
26
    public  $configPath;
27
    public  $configFile;
28
    private $moduleDirName = 'xoositemap';
29
30
    /**
31
     * Xoositemap\Preferences constructor.
32
     */
33
    public function __construct()
34
    {
35
        $xoops = \Xoops::getInstance();
0 ignored issues
show
The assignment to $xoops is dead and can be removed.
Loading history...
36
        $this->configFile = 'config.' . $this->moduleDirName . '.php';
37
38
        $this->configPath = \XoopsBaseConfig::get('var-path') . '/configs/' . $this->moduleDirName . '/';
39
40
        $this->basicConfig = $this->loadBasicConfig();
41
        $this->config      = @$this->loadConfig();
42
43
        if (count($this->config) != count($this->basicConfig)) {
44
            $this->config = array_merge($this->basicConfig, $this->config);
45
            $this->writeConfig($this->config);
46
        }
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    public static function getInstance()
53
    {
54
        static $instance;
55
        if (!isset($instance)) {
56
            $class    = __CLASS__;
57
            $instance = new $class();
58
        }
59
60
        return $instance;
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    public function getConfig()
67
    {
68
        return $this->config;
69
    }
70
71
    /**
72
     * Xoositemap\Preferences::loadConfig()
73
     *
74
     * @return array
75
     */
76
    public function loadConfig()
77
    {
78
        if (!$config = $this->readConfig()) {
79
            $config = $this->loadBasicConfig();
80
            $this->writeConfig($config);
81
        }
82
83
        return $config;
84
    }
85
86
    /**
87
     * Xoositemap\Preferences::loadBasicConfig()
88
     *
89
     * @return array
90
     */
91
    public function loadBasicConfig()
92
    {
93
        if (file_exists($file_path = dirname(__DIR__) . '/include/' . $this->configFile)) {
94
            $config = include $file_path;
95
        }
96
97
        return $config;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $config does not seem to be defined for all execution paths leading up to this point.
Loading history...
98
    }
99
100
    /**
101
     * Xoositemap\Preferences::readConfig()
102
     *
103
     * @return array
104
     */
105
    public function readConfig()
106
    {
107
        $file_path = $this->configPath . $this->configFile;
108
        \XoopsLoad::load('XoopsFile');
109
        $file = \XoopsFile::getHandler('file', $file_path);
110
111
        return eval(@$file->read());
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
112
    }
113
114
    /**
115
     * Xoositemap\Preferences::writeConfig()
116
     *
117
     * @param  array $config
118
     * @return bool|null
119
     * @internal param string $filename
120
     */
121
    public function writeConfig($config)
122
    {
123
        if ($this->createPath($this->configPath)) {
124
            $file_path = $this->configPath . $this->configFile;
125
            \XoopsLoad::load('XoopsFile');
126
            $file = \XoopsFile::getHandler('file', $file_path);
127
128
            return $file->write('return ' . var_export($config, true) . ';');
0 ignored issues
show
The method write() does not exist on XoopsFolderHandler. ( Ignorable by Annotation )

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

128
            return $file->/** @scrutinizer ignore-call */ write('return ' . var_export($config, true) . ';');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
129
        }
130
131
        return null;
132
    }
133
134
    /**
135
     * @param              $pathname
136
     * @param mixed|string $pathout
137
     * @return bool
138
     */
139
    private function createPath($pathname, $pathout = XOOPS_ROOT_PATH)
140
    {
141
        $xoops = \Xoops::getInstance();
0 ignored issues
show
The assignment to $xoops is dead and can be removed.
Loading history...
142
        $pathname = mb_substr($pathname, mb_strlen(\XoopsBaseConfig::get('root-path')));
143
        $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname);
144
145
        $dest  = $pathout;
146
        $paths = explode('/', $pathname);
147
148
        foreach ($paths as $path) {
149
            if (!empty($path)) {
150
                $dest = $dest . '/' . $path;
151
                if (!is_dir($dest)) {
152
                    if (!mkdir($dest, 0755) && !is_dir($dest)) {
153
                        return false;
154
                    }
155
                    $this->writeIndex(\XoopsBaseConfig::get('uploads-path'), 'index.html', $dest);
156
                }
157
            }
158
        }
159
160
        return true;
161
    }
162
163
    /**
164
     * @param $folder_in
165
     * @param $source_file
166
     * @param $folder_out
167
     * @return bool
168
     */
169
    private function writeIndex($folder_in, $source_file, $folder_out)
170
    {
171
        if (!is_dir($folder_out)) {
172
            if (!$this->createPath($folder_out)) {
173
                return false;
174
            }
175
        }
176
177
        // Simple copy for a file
178
        if (is_file($folder_in . '/' . $source_file)) {
179
            return copy($folder_in . '/' . $source_file, $folder_out . '/' . basename($source_file));
180
        }
181
182
        return false;
183
    }
184
185
    /**
186
     * @param null      $data
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $data is correct as it would always require null to be passed?
Loading history...
187
     * @param bool|true $module
188
     * @return array
189
     */
190
    public function prepare2Save($data = null, $module = true)
191
    {
192
        if (!isset($data)) {
193
            $data = $_POST;
194
        }
195
196
        $config = [];
197
        foreach (array_keys($data) as $k) {
0 ignored issues
show
$data of type null is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

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

197
        foreach (array_keys(/** @scrutinizer ignore-type */ $data) as $k) {
Loading history...
198
            if (is_array($data[$k])) {
199
                $config[$k] = $this->prepare2Save($data[$k], false);
200
            } else {
201
                if (false !== mb_strpos($k, $this->moduleDirName . '_') || !$module) {
202
                    $config[$k] = $data[$k];
203
                }
204
            }
205
        }
206
207
        return $config;
208
    }
209
}
210