Issues (371)

Security Analysis    no vulnerabilities found

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

Severity
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Publisher\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright   XOOPS Project (https://xoops.org)
17
 * @license     https://www.fsf.org/copyleft/gpl.html GNU public license
18
 * @author      mamba <[email protected]>
19
 */
20
trait FilesManagement
21
{
22
    /**
23
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
24
     *
25
     * @param string $folder The full path of the directory to check
26
     *
27
     * @throws \RuntimeException
28
     */
29
    public static function createFolder($folder): void
30
    {
31
        try {
32
            if (!\is_dir($folder)) {
33
                if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
34
                    throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder));
35
                }
36
37
                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
38
            }
39
        } catch (\Throwable $e) {
40
            echo 'Caught exception: ', $e->getMessage(), '<br>';
41
        }
42
    }
43
44
    public static function copyFile(string $file, string $folder): bool
45
    {
46
        return \copy($file, $folder);
47
    }
48
49
    public static function recurseCopy(string $src, string $dst): void
50
    {
51
        $dir = \opendir($src);
52
        if (!\mkdir($dst) && !\is_dir($dst)) {
53
            throw new \RuntimeException(\sprintf('Directory "%s" was not created', $dst));
54
        }
55
        while (false !== ($file = \readdir($dir))) {
56
            if (('.' !== $file) && ('..' !== $file)) {
57
                if (\is_dir($src . '/' . $file)) {
58
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
59
                } else {
60
                    \copy($src . '/' . $file, $dst . '/' . $file);
61
                }
62
            }
63
        }
64
        \closedir($dir);
65
    }
66
67
    /**
68
     * Copy a file, or recursively copy a folder and its contents
69
     * @param string $source Source path
70
     * @param string $dest   Destination path
71
     * @return bool Returns true on success, false on failure
72
     * @author      Aidan Lister <[email protected]>
73
     * @version     1.0.1
74
     * @link        https://aidanlister.com/2004/04/recursively-copying-directories-in-php/
75
     */
76
    public static function xcopy($source, $dest)
77
    {
78
        // Check for symlinks
79
        if (\is_link($source)) {
80
            return \symlink(\readlink($source), $dest);
81
        }
82
83
        // Simple copy for a file
84
        if (\is_file($source)) {
85
            return \copy($source, $dest);
86
        }
87
88
        // Make destination directory
89
        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
90
            throw new \RuntimeException(\sprintf('Directory "%s" was not created', $dest));
91
        }
92
93
        // Loop through the folder
94
        $dir = \dir($source);
95
        if (false !== $dir) {
96
            while (false !== ($entry = $dir->read())) {
97
                // Skip pointers
98
                if ('.' === $entry || '..' === $entry) {
99
                    continue;
100
                }
101
                // Deep copy directories
102
                self::xcopy("$source/$entry", "$dest/$entry");
103
            }
104
            // Clean up
105
            $dir->close();
106
        }
107
108
        return true;
109
    }
110
111
    /**
112
     * Remove files and (sub)directories
113
     *
114
     * @param string $src source directory to delete
115
     *
116
     * @return bool true on success
117
     * @uses \Xmf\Module\Helper::isUserAdmin()
118
     *
119
     * @uses \Xmf\Module\Helper::getHelper()
120
     */
121
    public static function deleteDirectory($src)
122
    {
123
        // Only continue if user is a 'global' Admin
124
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
125
            return false;
126
        }
127
128
        $success = true;
129
        // remove old files
130
        $dirInfo = new \SplFileInfo($src);
131
        // validate is a directory
132
        if ($dirInfo->isDir()) {
133
            $fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']);
134
            foreach ($fileList as $k => $v) {
135
                $fileInfo = new \SplFileInfo("{$src}/{$v}");
136
                if ($fileInfo->isDir()) {
137
                    // recursively handle subdirectories
138
                    if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
139
                        break;
140
                    }
141
                } elseif (!($success = \unlink($fileInfo->getRealPath()))) {
142
                    break;
143
                }
144
            }
145
            // now delete this (sub)directory if all the files are gone
146
            if ($success) {
147
                $success = \rmdir($dirInfo->getRealPath());
148
            }
149
        } else {
150
            // input is not a valid directory
151
            $success = false;
152
        }
153
154
        return $success;
155
    }
156
157
    /**
158
     * Recursively remove directory
159
     *
160
     * @todo currently won't remove directories with hidden files, should it?
161
     *
162
     * @param string $src directory to remove (delete)
163
     *
164
     * @return bool true on success
165
     */
166
    public static function rrmdir($src)
167
    {
168
        // Only continue if user is a 'global' Admin
169
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
170
            return false;
171
        }
172
173
        // If source is not a directory stop processing
174
        if (!\is_dir($src)) {
175
            return false;
176
        }
177
178
        $success = true;
0 ignored issues
show
The assignment to $success is dead and can be removed.
Loading history...
179
180
        // Open the source directory to read in files
181
        $iterator = new \DirectoryIterator($src);
182
        foreach ($iterator as $fObj) {
183
            if ($fObj->isFile()) {
184
                $filename = $fObj->getPathname();
185
                $fObj     = null; // clear this iterator object to close the file
0 ignored issues
show
The assignment to $fObj is dead and can be removed.
Loading history...
186
                if (!\unlink($filename)) {
187
                    return false; // couldn't delete the file
188
                }
189
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
190
                // Try recursively on directory
191
                self::rrmdir($fObj->getPathname());
192
            }
193
        }
194
        $iterator = null;   // clear iterator Obj to close file/directory
0 ignored issues
show
The assignment to $iterator is dead and can be removed.
Loading history...
195
196
        return \rmdir($src); // remove the directory & return results
197
    }
198
199
    /**
200
     * Recursively move files from one directory to another
201
     *
202
     * @param string $src  - Source of files being moved
203
     * @param string $dest - Destination of files being moved
204
     *
205
     * @return bool true on success
206
     */
207
    public static function rmove($src, $dest)
208
    {
209
        // Only continue if user is a 'global' Admin
210
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
211
            return false;
212
        }
213
214
        // If source is not a directory stop processing
215
        if (!\is_dir($src)) {
216
            return false;
217
        }
218
219
        // If the destination directory does not exist and could not be created stop processing
220
        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
221
            return false;
222
        }
223
224
        // Open the source directory to read in files
225
        $iterator = new \DirectoryIterator($src);
226
        foreach ($iterator as $fObj) {
227
            if ($fObj->isFile()) {
228
                \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
229
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
230
                // Try recursively on directory
231
                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
232
                //                rmdir($fObj->getPath()); // now delete the directory
233
            }
234
        }
235
        $iterator = null;   // clear iterator Obj to close file/directory
0 ignored issues
show
The assignment to $iterator is dead and can be removed.
Loading history...
236
237
        return \rmdir($src); // remove the directory & return results
238
    }
239
240
    /**
241
     * Recursively copy directories and files from one directory to another
242
     *
243
     * @param string $src  - Source of files being moved
244
     * @param string $dest - Destination of files being moved
245
     *
246
     * @return bool true on success
247
     * @uses \Xmf\Module\Helper::isUserAdmin()
248
     *
249
     * @uses \Xmf\Module\Helper::getHelper()
250
     */
251
    public static function rcopy($src, $dest)
252
    {
253
        // Only continue if user is a 'global' Admin
254
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
255
            return false;
256
        }
257
258
        // If source is not a directory stop processing
259
        if (!\is_dir($src)) {
260
            return false;
261
        }
262
263
        // If the destination directory does not exist and could not be created stop processing
264
        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
265
            return false;
266
        }
267
268
        // Open the source directory to read in files
269
        $iterator = new \DirectoryIterator($src);
270
        foreach ($iterator as $fObj) {
271
            if ($fObj->isFile()) {
272
                \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
273
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
274
                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
275
            }
276
        }
277
278
        return true;
279
    }
280
}
281