Issues (81)

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/Controller/Settings.php (3 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
 * @author Joas Schilling <[email protected]>
4
 * @author Lukas Reschke <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2016, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Activity\Controller;
24
25
use OCA\Activity\Data;
26
use OCA\Activity\UserSettings;
27
use OCP\Activity\IExtension;
28
use OCP\AppFramework\Controller;
29
use OCP\AppFramework\Http\DataResponse;
30
use OCP\AppFramework\Http\TemplateResponse;
31
use OCP\IConfig;
32
use OCP\IL10N;
33
use OCP\IRequest;
34
use OCP\IURLGenerator;
35
use OCP\IUser;
36
use OCP\Security\ISecureRandom;
37
38
class Settings extends Controller {
39
	/** @var \OCP\IConfig */
40
	protected $config;
41
42
	/** @var \OCP\Security\ISecureRandom */
43
	protected $random;
44
45
	/** @var \OCP\IURLGenerator */
46
	protected $urlGenerator;
47
48
	/** @var \OCA\Activity\Data */
49
	protected $data;
50
51
	/** @var \OCA\Activity\UserSettings */
52
	protected $userSettings;
53
54
	/** @var \OCP\IL10N */
55
	protected $l10n;
56
57
	/** @var IUser */
58
	protected $user;
59
60
	/**
61
	 * constructor of the controller
62
	 *
63
	 * @param string $appName
64
	 * @param IRequest $request
65
	 * @param IConfig $config
66
	 * @param ISecureRandom $random
67
	 * @param IURLGenerator $urlGenerator
68
	 * @param Data $data
69
	 * @param UserSettings $userSettings
70
	 * @param IL10N $l10n
71
	 * @param IUser $user
72
	 */
73 14 View Code Duplication
	public function __construct($appName,
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...
74
								IRequest $request,
75
								IConfig $config,
76
								ISecureRandom $random,
77
								IURLGenerator $urlGenerator,
78
								Data $data,
79
								UserSettings $userSettings,
80
								IL10N $l10n,
81
								IUser $user) {
82 14
		parent::__construct($appName, $request);
83 14
		$this->config = $config;
84 14
		$this->random = $random;
85 14
		$this->urlGenerator = $urlGenerator;
86 14
		$this->data = $data;
87 14
		$this->userSettings = $userSettings;
88 14
		$this->l10n = $l10n;
89 14
		$this->user = $user;
90 14
	}
91
92
	/**
93
	 * @NoAdminRequired
94
	 *
95
	 * @param int $notify_setting_batchtime
96
	 * @param bool $notify_setting_self
97
	 * @param bool $notify_setting_selfemail
98
	 * @return DataResponse
99
	 */
100 3
	public function personal(
101
			$notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
102
			$notify_setting_self = false,
103
			$notify_setting_selfemail = false) {
104 3
		$types = $this->data->getNotificationTypes($this->l10n);
105
106 3
		foreach ($types as $type => $data) {
107 3 View Code Duplication
			if (!\is_array($data) || (isset($data['methods']) && \in_array(IExtension::METHOD_MAIL, $data['methods']))) {
0 ignored issues
show
This code seems to be duplicated across 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...
108 3
				$this->config->setUserValue(
109 3
					$this->user->getUID(), 'activity',
110 3
					'notify_email_' . $type,
111 3
					(int) $this->request->getParam($type . '_email', false)
112
				);
113
			}
114
115 3 View Code Duplication
			if (!\is_array($data) || (isset($data['methods']) && \in_array(IExtension::METHOD_STREAM, $data['methods']))) {
0 ignored issues
show
This code seems to be duplicated across 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...
116 3
				$this->config->setUserValue(
117 3
					$this->user->getUID(), 'activity',
118 3
					'notify_stream_' . $type,
119 3
					(int) $this->request->getParam($type . '_stream', false)
120
				);
121
			}
122
		}
123
124 3
		$email_batch_time = 3600;
125 3
		if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
126 1
			$email_batch_time = 3600 * 24;
127 2
		} elseif ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
128 1
			$email_batch_time = 3600 * 24 * 7;
129
		}
130
131 3
		$this->config->setUserValue(
132 3
			$this->user->getUID(), 'activity',
133 3
			'notify_setting_batchtime',
134 3
			$email_batch_time
135
		);
136 3
		$this->config->setUserValue(
137 3
			$this->user->getUID(), 'activity',
138 3
			'notify_setting_self',
139 3
			(int) $notify_setting_self
140
		);
141 3
		$this->config->setUserValue(
142 3
			$this->user->getUID(), 'activity',
143 3
			'notify_setting_selfemail',
144 3
			(int) $notify_setting_selfemail
145
		);
146
147 3
		return new DataResponse([
148
			'data'		=> [
149 3
				'message'	=> (string) $this->l10n->t('Your settings have been updated.'),
150
			],
151
		]);
152
	}
153
154
	/**
155
	 * @NoAdminRequired
156
	 * @NoCSRFRequired
157
	 *
158
	 * @return TemplateResponse
159
	 */
160 8
	public function displayPanel() {
161 8
		$types = $this->data->getNotificationTypes($this->l10n);
162
163 8
		$activities = [];
164 8
		foreach ($types as $type => $desc) {
165 1
			if (\is_array($desc)) {
166 1
				$methods = isset($desc['methods']) ? $desc['methods'] : [IExtension::METHOD_STREAM, IExtension::METHOD_MAIL];
167 1
				$desc = isset($desc['desc']) ? $desc['desc'] : '';
168
			} else {
169 1
				$methods = [IExtension::METHOD_STREAM, IExtension::METHOD_MAIL];
170
			}
171
172 1
			$activities[$type] = [
173 1
				'desc'		=> $desc,
174 1
				IExtension::METHOD_MAIL		=> $this->userSettings->getUserSetting($this->user->getUID(), 'email', $type),
175 1
				IExtension::METHOD_STREAM	=> $this->userSettings->getUserSetting($this->user->getUID(), 'stream', $type),
176 1
				'methods'	=> $methods,
177
			];
178
		}
179
180 8
		$settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
181 8
		$currentSetting = (int) $this->userSettings->getUserSetting($this->user->getUID(), 'setting', 'batchtime');
182 8
		if ($currentSetting === 3600 * 24 * 7) {
183 1
			$settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY;
184 7
		} elseif ($currentSetting === 3600 * 24) {
185 1
			$settingBatchTime = UserSettings::EMAIL_SEND_DAILY;
186
		}
187
188 8
		return new TemplateResponse('activity', 'personal', [
189 8
			'activities'		=> $activities,
190 8
			'activity_email'	=> $this->user->getEMailAddress(),
191
192 8
			'setting_batchtime'	=> $settingBatchTime,
193
194 8
			'notify_self'		=> $this->userSettings->getUserSetting($this->user->getUID(), 'setting', 'self'),
195 8
			'notify_selfemail'	=> $this->userSettings->getUserSetting($this->user->getUID(), 'setting', 'selfemail'),
196
197
			'methods'			=> [
198 8
				IExtension::METHOD_MAIL => $this->l10n->t('Mail'),
199 8
				IExtension::METHOD_STREAM => $this->l10n->t('Stream'),
200
			],
201 8
		], '');
202
	}
203
204
	/**
205
	 * @NoAdminRequired
206
	 *
207
	 * @param string $enable	'true' if the feed is enabled
208
	 * @return DataResponse
209
	 */
210 2
	public function feed($enable) {
211 2
		$token = $tokenUrl = '';
212
213 2
		if ($enable === 'true') {
214 1
			$conflicts = true;
215
216
			// Check for collisions
217 1
			while (!empty($conflicts)) {
218 1
				$token = $this->random->generate(30);
219 1
				$conflicts = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
220
			}
221
222 1
			$tokenUrl = $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $token]);
223
		}
224
225 2
		$this->config->setUserValue($this->user->getUID(), 'activity', 'rsstoken', $token);
226
227 2
		return new DataResponse([
228
			'data'		=> [
229 2
				'message'	=> (string) $this->l10n->t('Your settings have been updated.'),
230 2
				'rsslink'	=> $tokenUrl,
231
			],
232
		]);
233
	}
234
}
235