Issues (1107)

Security Analysis    not enabled

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.

lib/elFinderSession.php (13 issues)

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
 * elFinder - file manager for web.
5
 * Session Wrapper Class.
6
 *
7
 * @author Naoki Sawada
8
 **/
9
class elFinderSession implements elFinderSessionInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    protected $started = false;
12
13
    protected $keys = [];
14
15
    protected $base64encode = false;
16
17
    protected $opts = [
18
        'base64encode' => false,
19
        'keys' => [
20
            'default' => 'elFinderCaches',
21
            'netvolume' => 'elFinderNetVolumes',
22
        ],
23
    ];
24
25
    public function __construct($opts)
26
    {
27
        $this->opts = array_merge($this->opts, $opts);
28
        $this->base64encode = ! empty($this->opts['base64encode']);
29
        $this->keys = $this->opts['keys'];
30
31
        return $this;
0 ignored issues
show
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function start()
38
    {
39
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
40
            if (session_status() !== PHP_SESSION_ACTIVE) {
41
                session_start();
42
            }
43
        } else {
44
            set_error_handler([$this, 'session_start_error'], E_NOTICE);
45
            session_start();
46
            restore_error_handler();
47
        }
48
        $this->started = session_id() ? true : false;
49
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function close()
57
    {
58
        if ($this->started) {
59
            session_write_close();
60
        }
61
        $this->started = false;
62
63
        return $this;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function get($key, $empty = null)
70
    {
71
        $closed = false;
72
        if (! $this->started) {
73
            $closed = true;
74
            $this->start();
75
        }
76
77
        $data = null;
78
79
        if ($this->started) {
80
            $session = &$this->getSessionRef($key);
81
            $data = $session;
82
            if ($data && $this->base64encode) {
83
                $data = $this->decodeData($data);
84
            }
85
        }
86
87
        $checkFn = null;
88
        if (! is_null($empty)) {
89
            if (is_string($empty)) {
90
                $checkFn = 'is_string';
91
            } elseif (is_array($empty)) {
92
                $checkFn = 'is_array';
93
            } elseif (is_object($empty)) {
94
                $checkFn = 'is_object';
95
            } elseif (is_float($empty)) {
96
                $checkFn = 'is_float';
97
            } elseif (is_int($empty)) {
98
                $checkFn = 'is_int';
99
            }
100
        }
101
102
        if (is_null($data) || ($checkFn && ! $checkFn($data))) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $checkFn of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
103
            $session = $data = $empty;
104
        }
105
106
        if ($closed) {
107
            $this->close();
108
        }
109
110
        return $data;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function set($key, $data)
117
    {
118
        $closed = false;
119
        if (! $this->started) {
120
            $closed = true;
121
            $this->start();
122
        }
123
        $session = &$this->getSessionRef($key);
124
        if ($this->base64encode) {
125
            $data = $this->encodeData($data);
126
        }
127
        $session = $data;
128
129
        if ($closed) {
130
            $this->close();
131
        }
132
133
        return $this;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function remove($key)
0 ignored issues
show
remove uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
140
    {
141
        $closed = false;
142
        if (! $this->started) {
143
            $closed = true;
144
            $this->start();
145
        }
146
147
        list($cat, $name) = array_pad(explode('.', $key, 2), 2, null);
148 View Code Duplication
        if (is_null($name)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
            if (! isset($this->keys[$cat])) {
150
                $name = $cat;
151
                $cat = 'default';
152
            }
153
        }
154 View Code Duplication
        if (isset($this->keys[$cat])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
            $cat = $this->keys[$cat];
156
        } else {
157
            $name = $cat.'.'.$name;
158
            $cat = $this->keys['default'];
159
        }
160
        if (is_null($name)) {
161
            unset($_SESSION[$cat]);
162
        } else {
163
            if (isset($_SESSION[$cat]) && is_array($_SESSION[$cat])) {
164
                unset($_SESSION[$cat][$name]);
165
            }
166
        }
167
168
        if ($closed) {
169
            $this->close();
170
        }
171
172
        return $this;
173
    }
174
175
    protected function &getSessionRef($key)
0 ignored issues
show
getSessionRef uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
176
    {
177
        $session = null;
178
        if ($this->started) {
179
            list($cat, $name) = array_pad(explode('.', $key, 2), 2, null);
180 View Code Duplication
            if (is_null($name)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
                if (! isset($this->keys[$cat])) {
182
                    $name = $cat;
183
                    $cat = 'default';
184
                }
185
            }
186 View Code Duplication
            if (isset($this->keys[$cat])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
                $cat = $this->keys[$cat];
188
            } else {
189
                $name = $cat.'.'.$name;
190
                $cat = $this->keys['default'];
191
            }
192
            if (is_null($name)) {
193
                if (! isset($_SESSION[$cat])) {
194
                    $_SESSION[$cat] = null;
195
                }
196
                $session = &$_SESSION[$cat];
197
            } else {
198 View Code Duplication
                if (! isset($_SESSION[$cat]) || ! is_array($_SESSION[$cat])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
199
                    $_SESSION[$cat] = [];
200
                }
201 View Code Duplication
                if (! isset($_SESSION[$cat][$name])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
202
                    $_SESSION[$cat][$name] = null;
203
                }
204
                $session = &$_SESSION[$cat][$name];
205
            }
206
        }
207
208
        return $session;
209
    }
210
211
    protected function encodeData($data)
212
    {
213
        if ($this->base64encode) {
214
            $data = base64_encode(serialize($data));
215
        }
216
217
        return $data;
218
    }
219
220
    protected function decodeData($data)
221
    {
222
        if ($this->base64encode) {
223
            if (is_string($data)) {
224
                if (($data = base64_decode($data)) !== false) {
225
                    $data = unserialize($data);
226
                } else {
227
                    $data = null;
228
                }
229
            } else {
230
                $data = null;
231
            }
232
        }
233
234
        return $data;
235
    }
236
237
    protected function session_start_error($errno, $errstr)
0 ignored issues
show
The parameter $errno is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $errstr is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
238
    {
239
    }
240
}
241