Issues (221)

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/Service/StackService.php (5 issues)

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
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 * @author Maxence Lange <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 *  This program is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU Affero General Public License as
12
 *  published by the Free Software Foundation, either version 3 of the
13
 *  License, or (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Affero General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Affero General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\Deck\Service;
26
27
use OCA\Deck\Activity\ActivityManager;
28
use OCA\Deck\Activity\ChangeSet;
29
use OCA\Deck\BadRequestException;
30
use OCA\Deck\Db\Acl;
31
use OCA\Deck\Db\AssignedUsersMapper;
32
use OCA\Deck\Db\BoardMapper;
33
use OCA\Deck\Db\CardMapper;
34
use OCA\Deck\Db\ChangeHelper;
35
use OCA\Deck\Db\LabelMapper;
36
use OCA\Deck\Db\Stack;
37
use OCA\Deck\Db\StackMapper;
38
use OCA\Deck\StatusException;
39
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
40
use Symfony\Component\EventDispatcher\GenericEvent;
41
42
43
class StackService {
44
45
	private $stackMapper;
46
	private $cardMapper;
47
	private $boardMapper;
48
	private $labelMapper;
49
	private $permissionService;
50
	private $boardService;
51
	private $cardService;
52
	private $assignedUsersMapper;
53
	private $attachmentService;
54
	private $activityManager;
55
	/** @var EventDispatcherInterface */
56
	private $eventDispatcher;
57
	private $changeHelper;
58
59
	public function __construct(
60
		StackMapper $stackMapper,
61
		BoardMapper $boardMapper,
62
		CardMapper $cardMapper,
63
		LabelMapper $labelMapper,
64
		PermissionService $permissionService,
65
		BoardService $boardService,
66
		CardService $cardService,
67
		AssignedUsersMapper $assignedUsersMapper,
68
		AttachmentService $attachmentService,
69
		ActivityManager $activityManager,
70
		EventDispatcherInterface $eventDispatcher,
71
		ChangeHelper $changeHelper
72
	) {
73
		$this->stackMapper = $stackMapper;
74
		$this->boardMapper = $boardMapper;
75
		$this->cardMapper = $cardMapper;
76
		$this->labelMapper = $labelMapper;
77
		$this->permissionService = $permissionService;
78
		$this->boardService = $boardService;
79
		$this->cardService = $cardService;
80
		$this->assignedUsersMapper = $assignedUsersMapper;
81
		$this->attachmentService = $attachmentService;
82
		$this->activityManager = $activityManager;
83
		$this->eventDispatcher = $eventDispatcher;
84
		$this->changeHelper = $changeHelper;
85
	}
86
87
	private function enrichStackWithCards($stack, $since = -1) {
88
		$cards = $this->cardMapper->findAll($stack->getId(), null, null, $since);
89
90
		if (\count($cards) === 0) {
91
			return;
92
		}
93
94
		foreach ($cards as $card) {
95
			$this->cardService->enrich($card);
96
		}
97
98
		$stack->setCards($cards);
99
	}
100
101
	private function enrichStacksWithCards($stacks, $since = -1) {
102
		foreach ($stacks as $stack) {
103
			$this->enrichStackWithCards($stack, $since);
104
		}
105
	}
106
107
	/**
108
	 * @param $stackId
109
	 *
110
	 * @return \OCP\AppFramework\Db\Entity
111
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
112
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
113
	 * @throws BadRequestException
114
	 */
115
	public function find($stackId) {
116
		if (is_numeric($stackId) === false) {
117
			throw new BadRequestException('stack id must be a number');
118
		}
119
120
		$stack = $this->stackMapper->find($stackId);
121
		$cards = $this->cardMapper->findAll($stackId);
122
		foreach ($cards as $cardIndex => $card) {
123
			$assignedUsers = $this->assignedUsersMapper->find($card->getId());
124
			$card->setAssignedUsers($assignedUsers);
125
			$card->setAttachmentCount($this->attachmentService->count($card->getId()));
126
		}
127
		$stack->setCards($cards);
128
129
		return $stack;
130
	}
131
132
	/**
133
	 * @param $boardId
134
	 *
135
	 * @return array
136
	 * @throws \OCA\Deck\NoPermissionException
137
	 * @throws BadRequestException
138
	 */
139
	public function findAll($boardId, $since = -1) {
140
		if (is_numeric($boardId) === false) {
141
			throw new BadRequestException('boardId must be a number');
142
		}
143
144
		$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
145
		$stacks = $this->stackMapper->findAll($boardId);
146
		$this->enrichStacksWithCards($stacks, $since);
147
148
		return $stacks;
149
	}
150
151
	public function fetchDeleted($boardId) {
152
		$this->permissionService->checkPermission(
153
			$this->boardMapper, $boardId, Acl::PERMISSION_READ
154
		);
155
		$stacks = $this->stackMapper->findDeleted($boardId);
156
		$this->enrichStacksWithCards($stacks);
157
158
		return $stacks;
159
	}
160
161
	/**
162
	 * @param $boardId
163
	 *
164
	 * @return array
165
	 * @throws \OCA\Deck\NoPermissionException
166
	 * @throws BadRequestException
167
	 */
168
	public function findAllArchived($boardId) {
169
170
		if (is_numeric($boardId) === false) {
171
			throw new BadRequestException('board id must be a number');
172
		}
173
174
		$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
175
		$stacks = $this->stackMapper->findAll($boardId);
176
		$labels = $this->labelMapper->getAssignedLabelsForBoard($boardId);
177
		foreach ($stacks as $stackIndex => $stack) {
178
			$cards = $this->cardMapper->findAllArchived($stack->id);
179
			foreach ($cards as $cardIndex => $card) {
180
				if (array_key_exists($card->id, $labels)) {
181
					$cards[$cardIndex]->setLabels($labels[$card->id]);
182
				}
183
			}
184
			$stacks[$stackIndex]->setCards($cards);
185
		}
186
187
		return $stacks;
188
	}
189
190
	/**
191
	 * @param $title
192
	 * @param $boardId
193
	 * @param integer $order
194
	 *
195
	 * @return \OCP\AppFramework\Db\Entity
196
	 * @throws StatusException
197
	 * @throws \OCA\Deck\NoPermissionException
198
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
199
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
200
	 * @throws BadRequestException
201
	 */
202
	public function create($title, $boardId, $order) {
203
204
		if ($title === false || $title === null) {
205
			throw new BadRequestException('title must be provided');
206
		}
207
208
		if (is_numeric($order) === false) {
209
			throw new BadRequestException('order must be a number');
210
		}
211
212
		if (is_numeric($boardId) === false) {
213
			throw new BadRequestException('board id must be a number');
214
		}
215
216
		$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
217
		if ($this->boardService->isArchived(null, $boardId)) {
218
			throw new StatusException('Operation not allowed. This board is archived.');
219
		}
220
		$stack = new Stack();
221
		$stack->setTitle($title);
222
		$stack->setBoardId($boardId);
223
		$stack->setOrder($order);
224
		$stack = $this->stackMapper->insert($stack);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::insert() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
225
		$this->activityManager->triggerEvent(
226
			ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE
227
		);
228
		$this->changeHelper->boardChanged($boardId);
229
230
		$this->eventDispatcher->dispatch(
231
			'\OCA\Deck\Stack::onCreate',
232
			new GenericEvent(null, ['id' => $stack->getId(), 'stack' => $stack])
233
		);
234
235
		return $stack;
236
	}
237
238
	/**
239
	 * @param $id
240
	 *
241
	 * @return \OCP\AppFramework\Db\Entity
242
	 * @throws \OCA\Deck\NoPermissionException
243
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
244
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
245
	 * @throws BadRequestException
246
	 */
247 View Code Duplication
	public function delete($id) {
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...
248
249
		if (is_numeric($id) === false) {
250
			throw new BadRequestException('stack id must be a number');
251
		}
252
253
		$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
254
255
		$stack = $this->stackMapper->find($id);
256
		$stack->setDeletedAt(time());
257
		$stack = $this->stackMapper->update($stack);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
258
259
		$this->activityManager->triggerEvent(
260
			ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE
261
		);
262
		$this->changeHelper->boardChanged($stack->getBoardId());
263
		$this->enrichStackWithCards($stack);
264
265
		$this->eventDispatcher->dispatch(
266
			'\OCA\Deck\Stack::onDelete', new GenericEvent(null, ['id' => $id, 'stack' => $stack])
267
		);
268
269
		return $stack;
270
	}
271
272
	/**
273
	 * @param $id
274
	 * @param $title
275
	 * @param $boardId
276
	 * @param $order
277
	 * @param $deletedAt
278
	 *
279
	 * @return \OCP\AppFramework\Db\Entity
280
	 * @throws StatusException
281
	 * @throws \OCA\Deck\NoPermissionException
282
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
283
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
284
	 * @throws BadRequestException
285
	 */
286
	public function update($id, $title, $boardId, $order, $deletedAt) {
287
288
		if (is_numeric($id) === false) {
289
			throw new BadRequestException('stack id must be a number');
290
		}
291
292
		if ($title === false || $title === null) {
293
			throw new BadRequestException('title must be provided');
294
		}
295
296
		if (is_numeric($boardId) === false) {
297
			throw new BadRequestException('board id must be a number');
298
		}
299
300
		if (is_numeric($order) === false) {
301
			throw new BadRequestException('order must be a number');
302
		}
303
304
		$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
305
		if ($this->boardService->isArchived($this->stackMapper, $id)) {
306
			throw new StatusException('Operation not allowed. This board is archived.');
307
		}
308
		$stack = $this->stackMapper->find($id);
309
		$changes = new ChangeSet($stack);
310
		$stack->setTitle($title);
311
		$stack->setBoardId($boardId);
312
		$stack->setOrder($order);
313
		$stack->setDeletedAt($deletedAt);
314
		$changes->setAfter($stack);
315
		$stack = $this->stackMapper->update($stack);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
316
		$this->activityManager->triggerUpdateEvents(
317
			ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE
318
		);
319
		$this->changeHelper->boardChanged($stack->getBoardId());
320
321
		$this->eventDispatcher->dispatch(
322
			'\OCA\Deck\Stack::onUpdate', new GenericEvent(null, ['id' => $id, 'stack' => $stack])
323
		);
324
325
		return $stack;
326
	}
327
328
	/**
329
	 * @param $id
330
	 * @param $order
331
	 *
332
	 * @return array
333
	 * @throws \OCA\Deck\NoPermissionException
334
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
335
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
336
	 * @throws BadRequestException
337
	 */
338
	public function reorder($id, $order) {
339
340
		if (is_numeric($id) === false) {
341
			throw new BadRquestException('id must be a number');
342
		}
343
344
		if ($order === false || $order === null) {
345
			throw new BadRequestException('order must be provided');
346
		}
347
348
		$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
349
		$stackToSort = $this->stackMapper->find($id);
350
		$stacks = $this->stackMapper->findAll($stackToSort->getBoardId());
351
		$result = [];
352
		$i = 0;
353
		foreach ($stacks as $stack) {
354
			if ($stack->id === $id) {
355
				$stack->setOrder($order);
356
			}
357
358
			if ($i === $order) {
359
				$i++;
360
			}
361
362
			if ($stack->id !== $id) {
363
				$stack->setOrder($i++);
364
			}
365
			$this->stackMapper->update($stack);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
366
			$result[$stack->getOrder()] = $stack;
367
		}
368
		$this->changeHelper->boardChanged($stackToSort->getBoardId());
369
370
		return $result;
371
	}
372
}
373