This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
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 Please refer to the PHP core documentation on constructors. ![]() |
|||
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);
}
}
![]() 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);
}
}
![]() 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);
}
}
![]() 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);
}
}
![]() 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);
}
}
![]() |
|||
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);
}
}
![]() |
|||
123 | // clear output buffer |
||
124 | while(@ob_get_level()){ @ob_end_clean(); } |
||
0 ignored issues
–
show
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.');
}
![]() |
|||
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 ![]() |
|||
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
![]() |
|||
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
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 ![]() |
|||
195 | } else { |
||
196 | if (!empty($data['raw']) && !empty($data['error'])) { |
||
197 | exit($data['error']); |
||
0 ignored issues
–
show
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 ![]() |
|||
198 | } else { |
||
199 | exit(json_encode($data)); |
||
0 ignored issues
–
show
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 ![]() |
|||
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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.