GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (29)

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/Operation/SaveOperation.php (1 issue)

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 ICanBoogie 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 ICanBoogie\Module\Operation;
13
14
use ICanBoogie\ActiveRecord;
15
use ICanBoogie\ActiveRecord\SchemaColumn;
16
use ICanBoogie\ErrorCollection;
17
use ICanBoogie\Module;
18
use ICanBoogie\Operation;
19
20
/**
21
 * The "save" operation is used to create or update a record.
22
 *
23
 * @property array $properties The properties to save.
24
 */
25
class SaveOperation extends Operation
26
{
27
	/**
28
	 * Change controls:
29
	 *
30
	 * - CONTROL_PERMISSION: Module::PERMISSION_CREATE
31
	 * - CONTROL_OWNERSHIP: true
32
	 * - CONTROL_FORM: true
33
	 *
34
	 * @return array
35
	 */
36 View Code Duplication
	protected function get_controls()
0 ignored issues
show
This method seems to be duplicated in 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...
37
	{
38
		return [
39
40
			self::CONTROL_PERMISSION => Module::PERMISSION_CREATE,
41
			self::CONTROL_RECORD => true,
42
			self::CONTROL_OWNERSHIP => true,
43
			self::CONTROL_FORM => true
44
45
		] + parent::get_controls();
46
	}
47
48
	/**
49
	 * Filters out the operation's parameters, which are not defined as fields by the
50
	 * primary model of the module, and take care of filtering or resolving properties values.
51
	 *
52
	 * Fields defined as 'boolean'
53
	 * ---------------------------
54
	 *
55
	 * The value of the property is filtered using the filter_var() function and the
56
	 * FILTER_VALIDATE_BOOLEAN filter. If the property in the operation params is empty, the
57
	 * property value is set the `false`.
58
	 *
59
	 * Fields defined as 'varchar'
60
	 * ---------------------------
61
	 *
62
	 * If the property is not empty in the operation params, the property value is trimmed using the
63
	 * trim() function, ensuring that there is no leading or trailing white spaces.
64
	 *
65
	 * **Note::** The getter should only be called during the {@link process()} method.
66
	 *
67
	 * @return array The properties of the operation.
68
	 */
69
	protected function lazy_get_properties()
70
	{
71
		$schema = $this->module->model->extended_schema;
72
		$request = $this->request;
73
		$properties = array_intersect_key($request->params, $schema->columns);
74
75
		foreach ($schema as $identifier => $column)
76
		{
77
			$type = $column->type;
78
79
			if ($type == SchemaColumn::TYPE_BOOLEAN)
80
			{
81
				if ($column->null && ($request[$identifier] === null || $request[$identifier] === ''))
82
				{
83
					$properties[$identifier] = null;
84
				}
85
				else
86
				{
87
					if (empty($properties[$identifier]))
88
					{
89
						$properties[$identifier] = false;
90
91
						continue;
92
					}
93
94
					$properties[$identifier] = filter_var($properties[$identifier], FILTER_VALIDATE_BOOLEAN);
95
				}
96
			}
97
			else if ($type == SchemaColumn::TYPE_VARCHAR)
98
			{
99
				if (empty($properties[$identifier]) || !is_string($properties[$identifier]))
100
				{
101
					continue;
102
				}
103
104
				$properties[$identifier] = trim($properties[$identifier]);
105
			}
106
		}
107
108
		unset($properties[$schema->primary]);
109
110
		return $properties;
111
	}
112
113
	/**
114
	 * Overrides the getter to prevent exceptions when the operation key is empty.
115
	 */
116
	protected function lazy_get_record()
117
	{
118
		return $this->key ? parent::lazy_get_record() : null;
119
	}
120
121
	/**
122
	 * Overrides the method in order for the control to pass if the operation key is empty, which
123
	 * is the case when creating a new record.
124
	 */
125
	protected function control_record()
126
	{
127
		return $this->key ? parent::control_record() : true;
128
	}
129
130
	/**
131
	 * The method simply returns true.
132
	 *
133
	 * @param ErrorCollection $errors
134
	 *
135
	 * @return bool
136
	 */
137
	protected function validate(ErrorCollection $errors)
138
	{
139
		return true;
140
	}
141
142
	/**
143
	 * Creates or updates a record in the module's primary model.
144
	 *
145
	 * A record is created if the operation's key is empty, otherwise an existing record is
146
	 * updated.
147
	 *
148
	 * The method uses the `properties` property to get the properties used to create or update
149
	 * the record.
150
	 *
151
	 * @return array An array composed of the save mode ('update' or 'new') and the record's
152
	 * key.
153
	 *
154
	 * @throws \RuntimeException when saving the record fails.
155
	 */
156
	protected function process()
157
	{
158
		$key = $this->key;
159
		$properties = $this->properties;
160
		$log_params = [ 'key' => $key, 'module' => $this->module->title ];
161
162
		try
163
		{
164
			$record_key = $key
165
				? $this->update_record($properties)
166
				: $this->create_record($properties, $this->record);
167
		}
168
		catch (ActiveRecord\RecordNotValid $e)
169
		{
170
			$this->response->errors->merge($e->errors->to_error_collection());
171
172
			throw $e;
173
		}
174
175
		if (!$record_key)
176
		{
177
			throw new \RuntimeException($this->format($key ? 'Unable to update record %key in %module.' : 'Unable to create record in %module.', $log_params));
178
		}
179
180
		$this->response->location = $this->request->uri;
181
		$this->response->message = $this->format($key ? 'The record %key in %module has been saved.' : 'A new record has been saved in %module.', $log_params);
182
183
		return [ 'mode' => $key ? 'update' : 'new', 'key' => $record_key ];
184
	}
185
186
	/**
187
	 * Update the operation record with properties.
188
	 *
189
	 * @param array $properties
190
	 *
191
	 * @return bool|int
192
	 */
193
	protected function update_record(array $properties)
194
	{
195
		return $this->record->assign($properties)->save();
196
	}
197
198
	/**
199
	 * Creates a record from properties.
200
	 *
201
	 * @param array $properties
202
	 * @param ActiveRecord $record The new record is saved in that variable.
203
	 *
204
	 * @return bool|int
205
	 */
206
	protected function create_record(array $properties, &$record)
207
	{
208
		$record = $this->module->model->new($properties);
209
210
		return $record->save();
211
	}
212
}
213