Issues (661)

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.

php/elFinderConnector.class.php (14 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
 * Default elFinder connector
5
 *
6
 * @author Dmitry (dio) Levashov
7
 **/
8
class elFinderConnector {
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...
9
	/**
10
	 * elFinder instance
11
	 *
12
	 * @var elFinder
13
	 **/
14
	protected $elFinder;
15
	
16
	/**
17
	 * Options
18
	 *
19
	 * @var aray
20
	 **/
21
	protected $options = array();
22
	
23
	/**
24
	 * undocumented class variable
25
	 *
26
	 * @var string
27
	 **/
28
	protected $header = 'Content-Type: application/json';
29
	
30
	
31
	/**
32
	 * Constructor
33
	 *
34
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
	 * @author Dmitry (dio) Levashov
36
	 **/
37
	public function __construct($elFinder, $debug=false) {
38
		
39
		$this->elFinder = $elFinder;
40
		if ($debug) {
41
			$this->header = 'Content-Type: text/html; charset=utf-8';
42
		}
43
	}
44
	
45
	/**
46
	 * Execute elFinder command and output result
47
	 *
48
	 * @return void
49
	 * @author Dmitry (dio) Levashov
50
	 **/
51
	public function run() {
0 ignored issues
show
run uses the super-global variable $_SERVER 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...
run uses the super-global variable $_POST 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...
run uses the super-global variable $_GET 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...
run uses the super-global variable $_REQUEST 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...
run uses the super-global variable $_FILES 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...
52
		$isPost = $_SERVER["REQUEST_METHOD"] == 'POST';
53
		$src    = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
54
		if ($isPost && !$src && $rawPostData = @file_get_contents('php://input')) {
55
			// for support IE XDomainRequest()
56
			$parts = explode('&', $rawPostData);
57
			foreach($parts as $part) {
58
				list($key, $value) = array_pad(explode('=', $part), 2, '');
59
				$key = rawurldecode($key);
60
				if (substr($key, -2) === '[]') {
61
					$key = substr($key, 0, strlen($key) - 2);
62
					if (!isset($src[$key])) {
63
						$src[$key] = array();
64
					}
65
					$src[$key][] = rawurldecode($value);
66
				} else {
67
					$src[$key] = rawurldecode($value);
68
				}
69
			}
70
			$_POST = $this->input_filter($src);
71
			$_REQUEST = $this->input_filter(array_merge_recursive($src, $_REQUEST));
72
		}
73
		$cmd    = isset($src['cmd']) ? $src['cmd'] : '';
74
		$args   = array();
75
		
76
		if (!function_exists('json_encode')) {
77
			$error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
78
			$this->output(array('error' => '{"error":["'.implode('","', $error).'"]}', 'raw' => true));
79
		}
80
		
81
		if (!$this->elFinder->loaded()) {
82
			$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
83
		}
84
		
85
		// telepat_mode: on
86
		if (!$cmd && $isPost) {
87
			$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
88
		}
89
		// telepat_mode: off
90
		
91
		if (!$this->elFinder->commandExists($cmd)) {
92
			$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
93
		}
94
		
95
		// collect required arguments to exec command
96
		foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
97
			$arg = $name == 'FILES' 
98
				? $_FILES 
99
				: (isset($src[$name]) ? $src[$name] : '');
100
				
101
			if (!is_array($arg)) {
102
				$arg = trim($arg);
103
			}
104
			if ($req && (!isset($arg) || $arg === '')) {
105
				$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
106
			}
107
			$args[$name] = $arg;
108
		}
109
		
110
		$args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
111
		
112
		$this->output($this->elFinder->exec($cmd, $this->input_filter($args)));
113
	}
114
	
115
	/**
116
	 * Output json
117
	 *
118
	 * @param  array  data to output
119
	 * @return void
120
	 * @author Dmitry (dio) Levashov
121
	 **/
122
	protected function output(array $data) {
0 ignored issues
show
output uses the super-global variable $_SERVER 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...
123
		// clear output buffer
124
		while(@ob_get_level()){ @ob_end_clean(); }
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...
125
		
126
		$header = isset($data['header']) ? $data['header'] : $this->header;
127
		unset($data['header']);
128
		if ($header) {
129
			if (is_array($header)) {
130
				foreach ($header as $h) {
131
					header($h);
132
				}
133
			} else {
134
				header($header);
135
			}
136
		}
137
		
138
		if (isset($data['pointer'])) {
139
			$toEnd = true;
140
			$fp = $data['pointer'];
141
			if (elFinder::isSeekableStream($fp)) {
142
				header('Accept-Ranges: bytes');
143
				$psize = null;
144
				if (!empty($_SERVER['HTTP_RANGE'])) {
145
					$size = $data['info']['size'];
146
					$start = 0;
0 ignored issues
show
$start is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
147
					$end = $size - 1;
148
					if (preg_match('/bytes=(\d*)-(\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) {
149
						if (empty($matches[3])) {
150
							if (empty($matches[1]) && $matches[1] !== '0') {
151
								$start = $size - $matches[2];
152
							} else {
153
								$start = intval($matches[1]);
154
								if (!empty($matches[2])) {
155
									$end = intval($matches[2]);
156
									if ($end >= $size) {
157
										$end = $size - 1;
158
									}
159
									$toEnd = ($end == ($size - 1));
160
								}
161
							}
162
							$psize = $end - $start + 1;
163
							
164
							header('HTTP/1.1 206 Partial Content');
165
							header('Content-Length: ' . $psize);
166
							header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size);
167
							
168
							fseek($fp, $start);
169
						}
170
					}
171
				}
172
				if (is_null($psize)){
173
					rewind($fp);
174
				}
175
			} else {
176
				header('Accept-Ranges: none');
177
			}
178
179
			// unlock session data for multiple access
180
			session_id() && session_write_close();
181
			// client disconnect should abort
182
			ignore_user_abort(false);
183
184
			if ($toEnd) {
185
				fpassthru($fp);
186
			} else {
187
				$out = fopen('php://output', 'wb');
188
				stream_copy_to_stream($fp, $out, $psize);
0 ignored issues
show
The variable $psize does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
189
				fclose($out);
190
			}
191
			if (!empty($data['volume'])) {
192
				$data['volume']->close($data['pointer'], $data['info']['hash']);
193
			}
194
			exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method output() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
195
		} else {
196
			if (!empty($data['raw']) && !empty($data['error'])) {
197
				exit($data['error']);
0 ignored issues
show
Coding Style Compatibility introduced by
The method output() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
198
			} else {
199
				exit(json_encode($data));
0 ignored issues
show
Coding Style Compatibility introduced by
The method output() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
200
			}
201
		}
202
		
203
	}
204
	
205
	/**
206
	 * Remove null & stripslashes applies on "magic_quotes_gpc"
207
	 * 
208
	 * @param  mixed  $args
209
	 * @return mixed
210
	 * @author Naoki Sawada
211
	 */
212
	protected function input_filter($args) {
213
		static $magic_quotes_gpc = NULL;
214
		
215
		if ($magic_quotes_gpc === NULL)
216
			$magic_quotes_gpc = (version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc());
217
		
218
		if (is_array($args)) {
219
			return array_map(array(& $this, 'input_filter'), $args);
220
		}
221
		$res = str_replace("\0", '', $args);
222
		$magic_quotes_gpc && ($res = stripslashes($res));
223
		return $res;
224
	}
225
}// END class 
226