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/LabelService.php (2 issues)

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
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Deck\Service;
25
26
use OCA\Deck\Db\ChangeHelper;
27
use OCA\Deck\Db\Label;
28
use OCA\Deck\Db\Acl;
29
use OCA\Deck\Db\LabelMapper;
30
use OCA\Deck\StatusException;
31
use OCA\Deck\BadRequestException;
32
33
34
class LabelService {
35
36
	/** @var LabelMapper */
37
	private $labelMapper;
38
	/** @var PermissionService */
39
	private $permissionService;
40
	/** @var BoardService */
41
	private $boardService;
42
	/** @var ChangeHelper */
43
	private $changeHelper;
44
45
	public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService, ChangeHelper $changeHelper) {
46
		$this->labelMapper = $labelMapper;
47
		$this->permissionService = $permissionService;
48
		$this->boardService = $boardService;
49
		$this->changeHelper = $changeHelper;
50
	}
51
52
	/**
53
	 * @param $labelId
54
	 * @return \OCP\AppFramework\Db\Entity
55
	 * @throws \OCA\Deck\NoPermissionException
56
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
57
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
58
	 * @throws BadRequestException
59
	 */
60
	public function find($labelId) {
61
		if (is_numeric($labelId) === false) {
62
			throw new BadRequestException('label id must be a number');
63
		}
64
		$this->permissionService->checkPermission($this->labelMapper, $labelId, Acl::PERMISSION_READ);
65
		return $this->labelMapper->find($labelId);
66
	}
67
68
	/**
69
	 * @param $title
70
	 * @param $color
71
	 * @param $boardId
72
	 * @return \OCP\AppFramework\Db\Entity
73
	 * @throws StatusException
74
	 * @throws \OCA\Deck\NoPermissionException
75
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
76
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
77
	 * @throws BadRequestException
78
	 */
79
	public function create($title, $color, $boardId) {
80
81
		if ($title === false || $title === null) {
82
			throw new BadRequestException('title must be provided');
83
		}
84
85
		if ($color === false || $color === null) {
86
			throw new BadRequestException('color must be provided');
87
		}
88
89
		if (is_numeric($boardId) === false) {
90
			throw new BadRequestException('board id must be a number');
91
		}
92
93
		$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
94
95
		$boardLabels = $this->labelMapper->findAll($boardId);
96
		if (\is_array($boardLabels)) {
97
			foreach($boardLabels as $boardLabel) {
98
				if ($boardLabel->getTitle() === $title) {
99
					throw new BadRequestException('title must be unique');
100
					break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
101
				}
102
			}
103
		}
104
105
		if ($this->boardService->isArchived(null, $boardId)) {
106
			throw new StatusException('Operation not allowed. This board is archived.');
107
		}
108
		$label = new Label();
109
		$label->setTitle($title);
110
		$label->setColor($color);
111
		$label->setBoardId($boardId);
112
		$this->changeHelper->boardChanged($boardId);
113
		return $this->labelMapper->insert($label);
114
	}
115
116
	/**
117
	 * @param $id
118
	 * @return \OCP\AppFramework\Db\Entity
119
	 * @throws StatusException
120
	 * @throws \OCA\Deck\NoPermissionException
121
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
122
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
123
	 * @throws BadRequestException
124
	 */
125
	public function delete($id) {
126
127
		if (is_numeric($id) === false) {
128
			throw new BadRequestException('label id must be a number');
129
		}
130
131
		$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
132
		if ($this->boardService->isArchived($this->labelMapper, $id)) {
133
			throw new StatusException('Operation not allowed. This board is archived.');
134
		}
135
		$label = $this->labelMapper->delete($this->find($id));
136
		$this->changeHelper->boardChanged($label->getBoardId());
137
		return $label;
138
	}
139
140
	/**
141
	 * @param $id
142
	 * @param $title
143
	 * @param $color
144
	 * @return \OCP\AppFramework\Db\Entity
145
	 * @throws StatusException
146
	 * @throws \OCA\Deck\NoPermissionException
147
	 * @throws \OCP\AppFramework\Db\DoesNotExistException
148
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
149
	 * @throws BadRequestException
150
	 */
151
	public function update($id, $title, $color) {
152
153
		if (is_numeric($id) === false) {
154
			throw new BadRequestException('label id must be a number');
155
		}
156
157
		if ($title === false || $title === null || $title === "") {
158
			throw new BadRequestException('title must be provided');
159
		}
160
161
		if ($color === false || $color === null) {
162
			throw new BadRequestException('color must be provided');
163
		}
164
165
		$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
166
167
		$label = $this->find($id);
168
169
		$boardLabels = $this->labelMapper->findAll($label->getBoardId());
170
		if (\is_array($boardLabels)) {
171
			foreach($boardLabels as $boardLabel) {
172
				if ($boardLabel->getId() === $label->getId()) {
173
					continue;
174
				}
175
				if ($boardLabel->getTitle() === $title) {
176
					throw new BadRequestException('title must be unique');
177
					break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
178
				}
179
			}
180
		}
181
182
		if ($this->boardService->isArchived($this->labelMapper, $id)) {
183
			throw new StatusException('Operation not allowed. This board is archived.');
184
		}
185
186
		$label->setTitle($title);
187
		$label->setColor($color);
188
		$this->changeHelper->boardChanged($label->getBoardId());
189
		return $this->labelMapper->update($label);
190
	}
191
192
}
193