Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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.

models/Scanner.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @package File manager
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\file_manager\models;
11
12
use FilesystemIterator;
13
use gplcart\core\Hook;
14
use gplcart\core\Module;
15
use gplcart\modules\file_manager\helpers\Filter;
16
use LimitIterator;
17
18
/**
19
 * Manages basic behaviors and data related to File manager module
20
 */
21
class Scanner
22
{
23
24
    /**
25
     * Hook class instance
26
     * @var \gplcart\core\Hook $hook
27
     */
28
    protected $hook;
29
30
    /**
31
     * Module class instance
32
     * @var \gplcart\core\Module $module
33
     */
34
    protected $module;
35
36
    /**
37
     * @param Hook $hook
38
     * @param Module $module
39
     */
40
    public function __construct(Hook $hook, Module $module)
41
    {
42
        $this->hook = $hook;
43
        $this->module = $module;
44
    }
45
46
    /**
47
     * Returns an array of scanned files or counts them
48
     * @param string $directory
49
     * @param array $options
50
     * @return array|integer
51
     */
52
    public function scan($directory, array $options = array())
53
    {
54
        set_time_limit(0);
55
56
        $options += array(
57
            'sort' => null,
58
            'order' => null,
59
            'filter_key' => null,
60
            'filter_value' => null
61
        );
62
63
        $result = null;
64
        $this->hook->attach('module.file_manager.scan.before', $directory, $options, $result, $this);
65
66
        if (isset($result)) {
67
            return $result;
68
        }
69
70
        $filters = $this->getFilters();
71
        $iterator = new Filter(new FilesystemIterator($directory), $options, $filters);
72
73
        if (!empty($options['count'])) {
74
            return iterator_count($iterator);
75
        }
76
77
        if (!empty($options['limit'])) {
78
            list($page, $limit) = $options['limit'];
79
            $iterator = new LimitIterator($iterator, $page, $limit);
80
        }
81
82
        $result = iterator_to_array($iterator);
83
        $this->sort($result, $options['sort'], $options['order']);
84
85
        $this->hook->attach('module.file_manager.scan.after', $directory, $options, $result, $this);
86
        return $result;
87
    }
88
89
    /**
90
     * Sorts an array of files
91
     * @param array $files
92
     * @param string $sort
93
     * @param string $order
94
     */
95
    protected function sort(array &$files, $sort, $order)
96
    {
97
        $sorters = $this->getSorters();
98
99
        if (isset($sorters[$sort]['handlers']['sort'])) {
100
            $function = $sorters[$sort]['handlers']['sort'];
101
            // Suppress errors, see https://bugs.php.net/bug.php?id=50688
102
            @uasort($files, function ($a, $b) use ($function, $order) {
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
103
                return $function($a, $b, $order);
104
            });
105
        }
106
    }
107
108
    /**
109
     * Returns an array of supported filters
110
     * @return array
111
     */
112
    public function getFilters()
113
    {
114
        $filters = &gplcart_static('module.file_manager.filter.list');
115
116
        if (isset($filters)) {
117
            return $filters;
118
        }
119
120
        $filters = (array) gplcart_config_get(__DIR__ . '/../config/filters.php');
121
        $this->hook->attach('module.file_manager.filter.list', $filters, $this);
122
        return $filters;
123
    }
124
125
    /**
126
     * Returns an array of file sorters
127
     * @return array
128
     */
129
    public function getSorters()
130
    {
131
        $sorters = &gplcart_static('module.file_manager.sorter.list');
132
133
        if (isset($sorters)) {
134
            return $sorters;
135
        }
136
137
        $sorters = (array) gplcart_config_get(__DIR__ . '/../config/sorters.php');
138
        $this->hook->attach('module.file_manager.sorter.list', $sorters, $this);
139
        return $sorters;
140
    }
141
142
    /**
143
     * Returns a string with initial path to scan files
144
     * @param bool|null|string $absolute
145
     * @return string
146
     */
147
    public function getInitialPath($absolute = false)
148
    {
149
        $path = $this->module->getSettings('file_manager', 'initial_path');
150
        return $absolute ? gplcart_file_absolute($path) : $path;
151
    }
152
153
}
154