Issues (35)

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.

lib/Module.php (3 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
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Icybee\Modules\Files;
13
14
use ICanBoogie\ErrorCollection;
15
16
class Module extends \Icybee\Modules\Nodes\Module
17
{
18
	const OPERATION_UPLOAD = 'upload';
19
20
	/**
21
	 * Creates following directories, with their .htaccess file.
22
	 *
23
	 * - "/repository/tmp", allow from all
24
	 * - "/repository/files", allow from all
25
	 * - "/repository/files-index", deny from all
26
	 *
27
	 * @inheritdoc
28
	 */
29
	public function install(ErrorCollection $errors)
30
	{
31
		$repository = \ICanBoogie\REPOSITORY;
32
33
		#
34
		# $repository/tmp
35
		#
36
37
		$path = $repository . 'tmp';
38
39 View Code Duplication
		if (!file_exists($path))
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...
40
		{
41
			$parent = dirname($path);
42
43
			if (is_writable($parent))
44
			{
45
				mkdir($path);
46
47
				file_put_contents($path . DIRECTORY_SEPARATOR . '.htaccess', 'Deny from all');
48
			}
49
			else
50
			{
51
				$errors->add($this->id, "Unable to create %directory directory, its parent is not writable.", [ '%directory' => $path ]);
52
			}
53
		}
54
55
		#
56
		# $repository/files
57
		#
58
59
		$path = $repository . 'files';
60
61 View Code Duplication
		if (!file_exists($path))
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...
62
		{
63
			$parent = dirname($path);
64
65
			if (is_writable($parent))
66
			{
67
				mkdir($path);
68
69
				file_put_contents($path . DIRECTORY_SEPARATOR . '.htaccess', 'Allow from all');
70
			}
71
			else
72
			{
73
				$errors->add($this->id, "Unable to create %directory directory, its parent is not writable", [ '%directory' => $path ]);
74
			}
75
		}
76
77
		#
78
		# $repository/files-index
79
		#
80
81
		$path = $repository . 'files-index';
82
83 View Code Duplication
		if (!file_exists($path))
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...
84
		{
85
			$parent = dirname($path);
86
87
			if (is_writable($parent))
88
			{
89
				mkdir($path);
90
91
				file_put_contents($path . DIRECTORY_SEPARATOR . '.htaccess', 'Deny from all');
92
			}
93
			else
94
			{
95
				$errors->add($this->id, 'Unable to create %directory directory, its parent is not writable', [ '%directory' => $path ]);
96
			}
97
		}
98
99
		#
100
		# config: max_file_size
101
		#
102
103
		$this->app->registry["{$this->flat_id}.max_file_size"] = 16000;
104
105
		return parent::install($errors);
106
	}
107
108
	/**
109
	 * Checks that the "tmp" and "files" directories exist in the repository.
110
	 *
111
	 * @inheritdoc
112
	 */
113
	public function is_installed(ErrorCollection $errors)
114
	{
115
		$repository = \ICanBoogie\REPOSITORY;
116
117
		#
118
		# $repository/tmp
119
		#
120
121
		$path = $repository . 'tmp';
122
123
		if (!is_dir($path))
124
		{
125
			$errors->add($this->id, "The %directory directory is missing.", [ '%directory' => $path ]);
126
		}
127
128
		#
129
		# $repository/files
130
		#
131
132
		$path = $repository . 'files';
133
134
		if (!is_dir($path))
135
		{
136
			$errors->add($this->id, "The %directory directory is missing.", [ '%directory' => $path ]);
137
		}
138
139
		return parent::is_installed($errors);
140
	}
141
142
	public function clean_temporary_files($lifetime = 3600)
143
	{
144
		$path = \ICanBoogie\REPOSITORY . 'tmp';
145
146
		if (!is_dir($path))
147
		{
148
			\ICanBoogie\log_error('The directory %directory does not exists', [ '%directory' => $path ]);
149
150
			return;
151
		}
152
153
		if (!is_writable($path))
154
		{
155
			\ICanBoogie\log_error('The directory %directory is not writable', [ '%directory' => $path ]);
156
157
			return;
158
		}
159
160
		$dh = opendir($path);
161
162
		if (!$dh)
163
		{
164
			return;
165
		}
166
167
		$now = time();
168
		$location = getcwd();
169
170
		chdir($path);
171
172
		while ($file = readdir($dh))
173
		{
174
			if ($file{0} == '.')
175
			{
176
				continue;
177
			}
178
179
			$stat = stat($file);
180
181
			if ($now - $stat['ctime'] > $lifetime)
182
			{
183
				unlink($file);
184
185
				\ICanBoogie\log('The temporary file %file has been deleted form the repository %directory', [
186
187
					'%file' => $file,
188
					'%directory' => $path
189
190
				]);
191
			}
192
		}
193
194
		chdir($location);
195
196
		closedir($dh);
197
	}
198
}
199