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.

includes/Controller/Register.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\Controller;
3
4
use Redaxscript\Filter;
5
use Redaxscript\Hash;
6
use Redaxscript\Html;
7
use Redaxscript\Mailer;
8
use Redaxscript\Model;
9
use Redaxscript\Validator;
10
11
/**
12
 * children class to process the register request
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category Controller
18
 * @author Henry Ruhs
19
 * @author Balázs Szilágyi
20
 */
21
22
class Register extends ControllerAbstract
23
{
24
	/**
25
	 * process
26
	 *
27
	 * @since 3.0.0
28
	 *
29
	 * @return string
30
	 */
31
32 5
	public function process() : string
33
	{
34 5
		$groupModel = new Model\Group();
35 5
		$settingModel = new Model\Setting();
36 5
		$passwordHash = new Hash();
37 5
		$postArray = $this->_normalizePost($this->_sanitizePost());
38 5
		$validateArray = $this->_validatePost($postArray);
39
40
		/* validate post */
41
42 5
		if ($validateArray)
43
		{
44 3
			return $this->_error(
45
			[
46 3
				'route' => 'register',
47 3
				'message' => $validateArray
48
			]);
49
		}
50
51
		/* handle create */
52
53 2
		$passwordHash->init($postArray['password']);
54
		$createArray =
55
		[
56 2
			'name' => $postArray['name'],
57 2
			'user' => $postArray['user'],
58 2
			'password' => $passwordHash->getHash(),
59 2
			'email' => $postArray['email'],
60 2
			'language' => $this->_registry->get('language'),
61 2
			'groups' => $groupModel->getByAlias('members')?->id,
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
62 2
			'status' => $settingModel->get('verification') ? 0 : 1
63
		];
64 2
		if (!$this->_create($createArray))
65
		{
66
			return $this->_error(
67
			[
68
				'route' => 'register'
69
			]);
70
		}
71
72
		/* handle mail */
73
74
		$mailArray =
75
		[
76 2
			'name' => $postArray['name'],
77 2
			'user' => $postArray['user'],
78 2
			'email' => $postArray['email']
79
		];
80 2
		if (!$this->_mail($mailArray))
81
		{
82 1
			return $this->_error(
83
			[
84 1
				'route' => 'register',
85 1
				'message' => $this->_language->get('email_failed')
86
			]);
87
		}
88
89
		/* handle success */
90
91 1
		return $this->_success(
92
		[
93 1
			'route' => 'login',
94 1
			'timeout' => 2,
95 1
			'message' => $settingModel->get('verification') ? $this->_language->get('registration_verification') : $this->_language->get('registration_completed')
96
		]);
97
	}
98
99
	/**
100
	 * sanitize the post
101
	 *
102
	 * @since 4.0.0
103
	 *
104
	 * @return array
105
	 */
106
107 5
	protected function _sanitizePost() : array
108
	{
109 5
		$emailFilter = new Filter\Email();
110 5
		$numberFilter = new Filter\Number();
111 5
		$passwordFilter = new Filter\Password();
112 5
		$textFilter = new Filter\Text();
113 5
		$userFilter = new Filter\User();
114
115
		/* sanitize post */
116
117
		return
118
		[
119 5
			'name' => $textFilter->sanitize($this->_request->getPost('name')),
120 5
			'user' => $userFilter->sanitize($this->_request->getPost('user')),
121 5
			'password' => $passwordFilter->sanitize($this->_request->getPost('password')),
122 5
			'email' => $emailFilter->sanitize($this->_request->getPost('email')),
123 5
			'task' => $numberFilter->sanitize($this->_request->getPost('task')),
124 5
			'solution' => $textFilter->sanitize($this->_request->getPost('solution'))
125
		];
126
	}
127
128
	/**
129
	 * validate the post
130
	 *
131
	 * @since 3.0.0
132
	 *
133
	 * @param array $postArray array of the post
134
	 *
135
	 * @return array
136
	 */
137
138 5
	protected function _validatePost(array $postArray = []) : array
139
	{
140 5
		$nameValidator = new Validator\Name();
141 5
		$userValidator = new Validator\User();
142 5
		$passwordValidator = new Validator\Password();
143 5
		$emailValidator = new Validator\Email();
144 5
		$captchaValidator = new Validator\Captcha();
145 5
		$settingModel = new Model\Setting();
146 5
		$userModel = new Model\User();
147 5
		$validateArray = [];
148
149
		/* validate post */
150
151 5
		if (!$postArray['name'])
152
		{
153 1
			$validateArray[] = $this->_language->get('name_empty');
154
		}
155 4
		else if (!$nameValidator->validate($postArray['name']))
156
		{
157 1
			$validateArray[] = $this->_language->get('name_incorrect');
158
		}
159 5
		if (!$postArray['user'])
160
		{
161 1
			$validateArray[] = $this->_language->get('user_empty');
162
		}
163 4
		else if (!$userValidator->validate($postArray['user']))
164
		{
165 1
			$validateArray[] = $this->_language->get('user_incorrect');
166
		}
167 3
		else if ($userModel->getByUser($postArray['user'])?->id)
168
		{
169 1
			$validateArray[] = $this->_language->get('user_exists');
170
		}
171 5
		if (!$postArray['password'])
172
		{
173 1
			$validateArray[] = $this->_language->get('password_empty');
174
		}
175 4
		else if (!$passwordValidator->validate($postArray['password']))
176
		{
177 1
			$validateArray[] = $this->_language->get('password_incorrect');
178
		}
179 5
		if (!$postArray['email'])
180
		{
181 1
			$validateArray[] = $this->_language->get('email_empty');
182
		}
183 4
		else if (!$emailValidator->validate($postArray['email']))
184
		{
185 1
			$validateArray[] = $this->_language->get('email_incorrect');
186
		}
187 5
		if ($settingModel->get('captcha') > 0 && !$captchaValidator->validate($postArray['task'], $postArray['solution']))
188
		{
189 1
			$validateArray[] = $this->_language->get('captcha_incorrect');
190
		}
191 5
		return $validateArray;
192
	}
193
194
	/**
195
	 * create the user
196
	 *
197
	 * @since 3.0.0
198
	 *
199
	 * @param array $createArray
200
	 *
201
	 * @return bool
202
	 */
203
204 2
	protected function _create(array $createArray = []) : bool
205
	{
206 2
		$userModel = new Model\User();
207 2
		return $userModel->createByArray($createArray);
208
	}
209
210
	/**
211
	 * send the mail
212
	 *
213
	 * @since 3.0.0
214
	 *
215
	 * @param array $mailArray
216
	 *
217
	 * @return bool
218
	 */
219
220 1
	protected function _mail(array $mailArray = []) : bool
221
	{
222 1
		$settingModel = new Model\Setting();
223 1
		$urlLogin = $this->_registry->get('root') . '/' . $this->_registry->get('parameterRoute') . 'login';
224
225
		/* html element */
226
227 1
		$linkElement = new Html\Element();
228
		$linkElement
229 1
			->init('a',
230
			[
231 1
				'href' => $urlLogin
232
			])
233 1
			->text($urlLogin);
234
235
		/* prepare mail */
236
237
		$toArray =
238
		[
239 1
			$mailArray['name'] => $mailArray['email'],
240 1
			$settingModel->get('author') => $settingModel->get('notification') ? $settingModel->get('email') : null
241
		];
242
		$fromArray =
243
		[
244 1
			$mailArray['name'] => $mailArray['email']
245
		];
246 1
		$subject = $this->_language->get('registration');
247
		$bodyArray =
248
		[
249 1
			$this->_language->get('user') . $this->_language->get('colon') . ' ' . $mailArray['user'],
250 1
			'<br />',
251 1
			$this->_language->get('login') . $this->_language->get('colon') . ' ' . $linkElement
252
		];
253
254
		/* send mail */
255
256 1
		$mailer = new Mailer();
257 1
		$mailer->init($toArray, $fromArray, $subject, $bodyArray);
258 1
		return $mailer->send();
259
	}
260
}
261