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/Recover.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\Html;
6
use Redaxscript\Mailer;
7
use Redaxscript\Model;
8
use Redaxscript\Validator;
9
use function sha1;
10
11
/**
12
 * children class to process the recover 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 Recover extends ControllerAbstract
23
{
24
	/**
25
	 * process the class
26
	 *
27
	 * @since 3.0.0
28
	 *
29
	 * @return string
30
	 */
31
32 5
	public function process() : string
33
	{
34 5
		$postArray = $this->_normalizePost($this->_sanitizePost());
35 5
		$validateArray = $this->_validatePost($postArray);
36 5
		$users = $this->_getUsers($postArray);
37
38
		/* validate post */
39
40 5
		if ($validateArray)
41
		{
42 3
			return $this->_error(
43
			[
44 3
				'route' => 'login/recover',
45 3
				'message' => $validateArray
46
			]);
47
		}
48
49
		/* handle mail and validate user */
50
51 2
		$validateArray = [];
52 2
		foreach ($users as $user)
53
		{
54
			$mailArray =
55
			[
56 2
				'id' => $user->id,
57 2
				'name' => $user->name,
58 2
				'user' => $user->user,
59 2
				'password' => $user->password,
60 2
				'email' => $user->email
61
			];
62 2
			if (!$this->_mail($mailArray))
63
			{
64 1
				return $this->_error(
65
				[
66 1
					'route' => 'login/recover',
67 1
					'message' => $this->_language->get('email_failed')
68
				]);
69
			}
70 1
			$validateArray[] = $user->name . $this->_language->get('colon') . ' ' . $this->_language->get('recovery_sent');
71
		}
72 1
		if ($validateArray)
73
		{
74 1
			return $this->_success(
75
			[
76 1
				'route' => 'login',
77 1
				'timeout' => 2,
78 1
				'message' => $validateArray
79
			]);
80
		}
81
82
		/* handle error */
83
84
		return $this->_error(
85
		[
86
			'route' => 'login/recover'
87
		]);
88
	}
89
90
	/**
91
	 * sanitize the post
92
	 *
93
	 * @since 4.0.0
94
	 *
95
	 * @return array
96
	 */
97
98 5
	protected function _sanitizePost() : array
99
	{
100 5
		$emailFilter = new Filter\Email();
101 5
		$numberFilter = new Filter\Number();
102 5
		$textFilter = new Filter\Text();
103
104
		/* sanitize post */
105
106
		return
107
		[
108 5
			'email' => $emailFilter->sanitize($this->_request->getPost('email')),
109 5
			'task' => $numberFilter->sanitize($this->_request->getPost('task')),
110 5
			'solution' => $textFilter->sanitize($this->_request->getPost('solution'))
111
		];
112
	}
113
114
	/**
115
	 * validate the post
116
	 *
117
	 * @since 3.0.0
118
	 *
119
	 * @param array $postArray array of the post
120
	 *
121
	 * @return array
122
	 */
123
124 5
	protected function _validatePost(array $postArray = []) : array
125
	{
126 5
		$emailValidator = new Validator\Email();
127 5
		$captchaValidator = new Validator\Captcha();
128 5
		$userModel = new Model\User();
129 5
		$settingModel = new Model\Setting();
130 5
		$validateArray = [];
131
132
		/* validate post */
133
134 5
		if (!$postArray['email'])
135
		{
136 1
			$validateArray[] = $this->_language->get('email_empty');
137
		}
138 4
		else if (!$emailValidator->validate($postArray['email']))
139
		{
140 1
			$validateArray[] = $this->_language->get('email_incorrect');
141
		}
142 3
		else if (!$userModel->getByEmail($postArray['email'])?->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...
143
		{
144 1
			$validateArray[] = $this->_language->get('email_unknown');
145
		}
146 5
		if ($settingModel->get('captcha') > 0 && !$captchaValidator->validate($postArray['task'], $postArray['solution']))
147
		{
148 1
			$validateArray[] = $this->_language->get('captcha_incorrect');
149
		}
150 5
		return $validateArray;
151
	}
152
153
	/**
154
	 * get the users
155
	 *
156
	 * @since 4.0.0
157
	 *
158
	 * @param array $postArray array of the post
159
	 *
160
	 * @return object|null
161
	 */
162
163 5
	protected function _getUsers(array $postArray = []) : ?object
164
	{
165 5
		$userModel = new Model\User();
166
		return $userModel
167 5
			->query()
168 5
			->where(
169
			[
170 5
				'email' => $postArray['email'],
171 5
				'status' => 1
172
			])
173 5
			->findMany() ? : null;
174
	}
175
176
	/**
177
	 * send the mail
178
	 *
179
	 * @since 3.0.0
180
	 *
181
	 * @param array $mailArray array of the mail
182
	 *
183
	 * @return bool
184
	 */
185
186 1
	protected function _mail(array $mailArray = []) : bool
187
	{
188 1
		$settingModel = new Model\Setting();
189 1
		$urlReset = $this->_registry->get('root') . '/' . $this->_registry->get('parameterRoute') . 'login/reset/' . sha1($mailArray['password']) . '/' . $mailArray['id'];
190
191
		/* html element */
192
193 1
		$linkElement = new Html\Element();
194
		$linkElement
195 1
			->init('a',
196
			[
197 1
				'href' => $urlReset
198
			])
199 1
			->text($urlReset);
200
201
		/* prepare mail */
202
203
		$toArray =
204
		[
205 1
			$mailArray['name'] => $mailArray['email']
206
		];
207
		$fromArray =
208
		[
209 1
			$settingModel->get('author') => $settingModel->get('email')
210
		];
211 1
		$subject = $this->_language->get('recovery');
212
		$bodyArray =
213
		[
214 1
			$this->_language->get('user') . $this->_language->get('colon') . ' ' . $mailArray['user'],
215 1
			'<br />',
216 1
			$this->_language->get('password_reset') . $this->_language->get('colon') . ' ' . $linkElement
217
		];
218
219
		/* send mail */
220
221 1
		$mailer = new Mailer();
222 1
		$mailer->init($toArray, $fromArray, $subject, $bodyArray);
223 1
		return $mailer->send();
224
	}
225
}
226