Issues (201)

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.

modules/ImageUpload/ImageUpload.php (1 issue)

Labels
Severity

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
namespace Redaxscript\Modules\ImageUpload;
3
4
use Redaxscript\Filesystem;
5
use Redaxscript\Head;
6
use Redaxscript\Header;
7
use Redaxscript\Module;
8
use function chmod;
9
use function in_array;
10
use function is_dir;
11
use function json_encode;
12
use function mkdir;
13
use function move_uploaded_file;
14
use function pathinfo;
15
use function sha1_file;
16
17
/**
18
 * shared module to upload images
19
 *
20
 * @since 4.3.0
21
 *
22
 * @package Redaxscript
23
 * @category Modules
24
 * @author Henry Ruhs
25
 */
26
27
class ImageUpload extends Module\Metadata
28
{
29
	/**
30
	 * array of the module
31
	 *
32
	 * @var array
33
	 */
34
35
	protected static array $_moduleArray =
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
36
	[
37
		'name' => 'Image Upload',
38
		'alias' => 'ImageUpload',
39
		'author' => 'Redaxmedia',
40
		'description' => 'Shared module to upload images',
41
		'version' => '5.0.0',
42
		'license' => 'MIT',
43
		'access' => '[1]'
44
	];
45
46
	/**
47
	 * array of the option
48
	 *
49
	 * @var array
50
	 */
51
52
	protected array $_optionArray =
53
	[
54
		'uploadDirectory' => 'upload',
55
		'mimeTypeArray' =>
56
		[
57
			'image/gif',
58
			'image/jpeg',
59
			'image/png',
60
			'image/svg+xml'
61
		]
62
	];
63
64
	/**
65
	 * renderStart
66
	 *
67
	 * @since 4.3.0
68
	 */
69
70
	public function renderStart() : void
71
	{
72
		/* script */
73
74
		$script = Head\Script::getInstance();
75
		$script
76
			->init('foot')
77
			->appendFile(
78
			[
79
				'modules/ImageUpload/assets/scripts/init.js',
80
				'modules/ImageUpload/dist/scripts/image-upload.min.js'
81
			]);
82
83
		/* list and upload */
84
85
		if ($this->_registry->get('firstParameter') === 'module' && $this->_registry->get('secondParameter') === 'image-upload' && $this->_registry->get('tokenParameter'))
86
		{
87
			if ($this->_registry->get('thirdParameter') === 'list')
88
			{
89
				$this->_registry->set('renderBreak', true);
90
				echo $this->_list();
91
			}
92
			if ($this->_registry->get('thirdParameter') === 'upload')
93
			{
94
				$this->_registry->set('renderBreak', true);
95
				echo $this->_upload();
96
			}
97
		}
98
	}
99
100
	/**
101
	 * adminNotification
102
	 *
103
	 * @since 4.3.0
104
	 *
105
	 * @return array
106
	 */
107
108
	public function adminNotification() : array
109
	{
110
		if (!mkdir($directory = $this->_optionArray['uploadDirectory']) && !is_dir($directory))
111
		{
112
			$this->setNotification('error', $this->_language->get('directory_not_found') . $this->_language->get('colon') . ' ' . $this->_optionArray['uploadDirectory'] . $this->_language->get('point'));
113
		}
114
		else if (!chmod($this->_optionArray['uploadDirectory'], 0777))
115
		{
116
			$this->setNotification('error', $this->_language->get('directory_permission_grant') . $this->_language->get('colon') . ' ' . $this->_optionArray['uploadDirectory'] . $this->_language->get('point'));
117
		}
118
		return $this->getNotificationArray();
119
	}
120
121
	/**
122
	 * list
123
	 *
124
	 * @since 4.3.0
125
	 *
126
	 * @return string
127
	 */
128
129
	protected function _list() : string
130
	{
131
		$uploadFilesystem = new Filesystem\Filesystem();
132
		$uploadFilesystem->init($this->_optionArray['uploadDirectory']);
133
		$uploadFilesystemArray = $uploadFilesystem->getSortArray();
134
135
		/* handle list */
136
137
		Header::contentType('application/json');
138
		return json_encode($uploadFilesystemArray);
139
	}
140
141
	/**
142
	 * upload
143
	 *
144
	 * @since 4.3.0
145
	 *
146
	 * @return string
147
	 */
148
149
	protected function _upload() : ?string
150
	{
151
		$filesArray = $this->_request->getArray()['files'];
152
		$uploadArray = [];
153
154
		/* process files */
155
156
		foreach ($filesArray as $key => $file)
157
		{
158
			$fileExtension = pathinfo($file['name'], PATHINFO_EXTENSION);
159
			$fileName = sha1_file($file['tmp_name']) . '.' . $fileExtension;
160
			$uploadPath = $this->_optionArray['uploadDirectory'] . DIRECTORY_SEPARATOR . $fileName;
161
			if (in_array($file['type'], $this->_optionArray['mimeTypeArray']) && move_uploaded_file($file['tmp_name'], $uploadPath))
162
			{
163
				$uploadArray[] = $uploadPath;
164
			}
165
		}
166
167
		/* handle upload */
168
169
		Header::contentType('application/json');
170
		return json_encode($uploadArray);
171
	}
172
}
173