Issues (3882)

Security Analysis    39 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting (9)
Response Splitting can be used to send arbitrary responses.
  File Manipulation (2)
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.
  File Exposure (7)
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.
  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.
  Code Injection (13)
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  Cross-Site Scripting (8)
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.
  Header Injection
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.

app/BatchMethod.php (1 issue)

1
<?php
2
/**
3
 * Batch method file.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Radosław Skrzypczak <[email protected]>
10
 */
11
12
namespace App;
13
14
/**
15
 * Batch method class.
16
 */
17
class BatchMethod extends Base
18
{
19
	/** Enebled */
20
	const STATUS_ENABLED = 1;
21
22
	/** Running     */
23
	const STATUS_RUNNING = 2;
24
25
	/** Halted */
26
	const STATUS_HALTED = 3;
27
28
	/** Completed */
29
	const STATUS_COMPLETED = 4;
30
31
	/** @var array [name => type, ...] */
32
	protected $allowedFields = [
33
		'userid' => 'integer',
34
		'status' => 'integer',
35
		'params' => 'string',
36
		'method' => 'string',
37
	];
38
39
	/** Previous status */
40
	private $previousStatus;
41
42
	/**
43
	 * BatchMethod constructor.
44
	 *
45
	 * @param array $values
46
	 * @param bool  $encode
47
	 *
48 5770
	 * @throws \App\Exceptions\AppException
49
	 */
50 5770
	public function __construct($values = [], $encode = true)
51 5770
	{
52 5770
		$values['status'] = $values['status'] ?? static::STATUS_ENABLED;
53 5770
		$values['userid'] = $values['userid'] ?? User::getCurrentUserId();
54
		if ($encode) {
55 5770
			$values['params'] = Json::encode($values['params']);
56 5770
		}
57 5770
		parent::__construct($values);
58
		$this->previousStatus = $values['status'];
59
	}
60
61
	/**
62
	 * Save.
63
	 *
64 5770
	 * @return bool
65
	 */
66 5770
	public function save()
67 5770
	{
68
		$db = Db::getInstance('admin');
69
		if ($this->get('id')) {
70 5770
			$result = $db->createCommand()->update('s_#__batchmethod', $this->getData(), ['id' => $this->get('id')])->execute();
71 5766
		} else {
72
			if ($this->isExists()) {
73 5
				return false;
74 5
			}
75 5
			$this->value['created_time'] = date('Y-m-d H:i:s');
76
			$result = $db->createCommand()->insert('s_#__batchmethod', $this->getData())->execute();
77 5
			$this->value['id'] = $db->getLastInsertID('s_#__batchmethod_id_seq');
78 5
		}
79
		$this->previousStatus = $this->get('status');
80
		return (bool) $result;
81
	}
82
83
	/**
84
	 * Function verifies if a duplicate of the entry already exists.
85
	 *
86 5770
	 * @return bool
87
	 */
88 5770
	public function isExists(): bool
89
	{
90
		return (new Db\Query())->from('s_#__batchmethod')->where(['method' => $this->get('method'), 'params' => $this->get('params')])->exists(Db::getInstance('admin'));
91
	}
92
93
	/**
94 1
	 * Execute.
95
	 */
96
	public function execute()
97 1
	{
98 1
		try {
99 1
			$this->setStatus(static::STATUS_RUNNING);
100
			if (\is_callable($this->get('method'))) {
101
				\call_user_func_array($this->get('method'), Json::decode($this->get('params')));
102
			} else {
103 1
				throw new Exceptions\AppException("ERR_CONTENTS_VARIABLE_CANT_CALLED_FUNCTION||{$this->get('method')}", 406);
104
			}
105
			$this->setStatus(static::STATUS_COMPLETED);
106
		} catch (\Throwable $ex) {
107
			Log::error($ex->getMessage());
108
			if ($this->previousStatus === static::STATUS_HALTED) {
109
				$this->log($ex->__toString());
110
				$this->delete();
111
			} else {
112
				$this->setStatus(static::STATUS_HALTED);
113 1
			}
114
		}
115
	}
116
117
	/**
118
	 * Set status.
119
	 *
120 1
	 * @param int $status
121
	 */
122 1
	public function setStatus(int $status)
123 1
	{
124 1
		$result = Db::getInstance('admin')->createCommand()->update('s_#__batchmethod', ['status' => $status], ['id' => $this->get('id')])->execute();
125
		if ($result) {
126 1
			$this->set('status', $status);
127
		}
128
	}
129
130
	/**
131
	 * Function check is status completed.
132
	 *
133 1
	 * @return bool
134
	 */
135 1
	public function isCompleted()
136
	{
137
		return $this->get('status') === static::STATUS_COMPLETED;
138
	}
139
140
	/**
141 1
	 * Delete.
142
	 */
143 1
	public function delete()
144 1
	{
145
		Db::getInstance('admin')->createCommand()->delete('s_#__batchmethod', ['id' => $this->get('id')])->execute();
146
	}
147
148
	/**
149
	 * Delete entries with the same parameters.
150
	 */
151
	public function deleteDuplicate(): bool
152
	{
153
		return Db::getInstance('admin')->createCommand()->delete('s_#__batchmethod', ['method' => $this->get('method'), 'params' => $this->get('params')])->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Db::getInstan...('params')))->execute() returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
154
	}
155
156
	/**
157
	 * Delete by method.
158
	 *
159
	 * @param string $method
160
	 */
161
	public static function deleteByMethod(string $method): void
162
	{
163
		Db::getInstance('admin')->createCommand()->delete('s_#__batchmethod', ['method' => $method])->execute();
164
	}
165
166
	/**
167
	 * Log.
168
	 *
169
	 * @param string $message
170
	 */
171
	private function log($message)
172
	{
173
		Db::getInstance('log')->createCommand()->insert('l_#__batchmethod', [
174
			'status' => $this->get('status'),
175
			'date' => date('Y-m-d H:i:s'),
176
			'method' => $this->get('method'),
177
			'params' => $this->get('params'),
178
			'userid' => $this->get('userid'),
179
			'message' => $message,
180
		])->execute();
181
	}
182
}
183