Issues (159)

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 (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, ownCloud, Inc.
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 *
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
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, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\Activity\Controller;
25
26
use OCA\Activity\CurrentUser;
27
use OCA\Activity\UserSettings;
28
use OCP\Activity\IExtension;
29
use OCP\Activity\IManager;
30
use OCP\Activity\ISetting;
31
use OCP\AppFramework\Controller;
32
use OCP\AppFramework\Http\DataResponse;
33
use OCP\AppFramework\Http\TemplateResponse;
34
use OCP\IConfig;
35
use OCP\IL10N;
36
use OCP\IRequest;
37
use OCP\IURLGenerator;
38
use OCP\Security\ISecureRandom;
39
40
class Settings extends Controller {
41
	/** @var \OCP\IConfig */
42
	protected $config;
43
44
	/** @var \OCP\Security\ISecureRandom */
45
	protected $random;
46
47
	/** @var \OCP\IURLGenerator */
48
	protected $urlGenerator;
49
50
	/** @var IManager */
51
	protected $manager;
52
53
	/** @var \OCA\Activity\UserSettings */
54
	protected $userSettings;
55
56
	/** @var \OCP\IL10N */
57
	protected $l10n;
58
59
	/** @var string */
60
	protected $user;
61
62
	/**
63
	 * constructor of the controller
64
	 *
65
	 * @param string $appName
66
	 * @param IRequest $request
67
	 * @param IConfig $config
68
	 * @param ISecureRandom $random
69
	 * @param IURLGenerator $urlGenerator
70
	 * @param IManager $manager
71
	 * @param UserSettings $userSettings
72
	 * @param IL10N $l10n
73
	 * @param CurrentUser $currentUser
74
	 */
75 2 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...
76
								IRequest $request,
77
								IConfig $config,
78
								ISecureRandom $random,
79
								IURLGenerator $urlGenerator,
80
								IManager $manager,
81
								UserSettings $userSettings,
82
								IL10N $l10n,
83
								CurrentUser $currentUser) {
84 2
		parent::__construct($appName, $request);
85 2
		$this->config = $config;
86 2
		$this->random = $random;
87 2
		$this->urlGenerator = $urlGenerator;
88 2
		$this->manager = $manager;
89 2
		$this->userSettings = $userSettings;
90 2
		$this->l10n = $l10n;
91 2
		$this->user = (string) $currentUser->getUID();
92 2
	}
93
94
	/**
95
	 * @NoAdminRequired
96
	 *
97
	 * @param int $notify_setting_batchtime
98
	 * @param bool $notify_setting_self
99
	 * @param bool $notify_setting_selfemail
100
	 * @return DataResponse
101
	 */
102
	public function personal(
103
			$notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
104
			$notify_setting_self = false,
105
			$notify_setting_selfemail = false) {
106
107
		$settings = $this->manager->getSettings();
108 View Code Duplication
		foreach ($settings as $setting) {
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...
109
			if ($setting->canChangeStream()) {
110
				$this->config->setUserValue(
111
					$this->user, 'activity',
112
					'notify_stream_' . $setting->getIdentifier(),
113
					(int) $this->request->getParam($setting->getIdentifier() . '_stream', false)
114
				);
115
			}
116
117
			if ($setting->canChangeMail()) {
118
				$this->config->setUserValue(
119
					$this->user, 'activity',
120
					'notify_email_' . $setting->getIdentifier(),
121
					(int) $this->request->getParam($setting->getIdentifier() . '_email', false)
122
				);
123
			}
124
		}
125
126
		$email_batch_time = 3600;
127 View Code Duplication
		if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
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...
128
			$email_batch_time = 3600 * 24;
129
		} else if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
130
			$email_batch_time = 3600 * 24 * 7;
131
		} else if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_ASAP) {
132
			$email_batch_time = 0;
133
		}
134
135
		$this->config->setUserValue(
136
			$this->user, 'activity',
137
			'notify_setting_batchtime',
138
			$email_batch_time
139
		);
140
		$this->config->setUserValue(
141
			$this->user, 'activity',
142
			'notify_setting_self',
143
			(int) $notify_setting_self
144
		);
145
		$this->config->setUserValue(
146
			$this->user, 'activity',
147
			'notify_setting_selfemail',
148
			(int) $notify_setting_selfemail
149
		);
150
151
		return new DataResponse(array(
152
			'data'		=> array(
153
				'message'	=> (string) $this->l10n->t('Your settings have been updated.'),
154
			),
155
		));
156
	}
157
158
	/**
159
	 * @param int $notify_setting_batchtime
160
	 * @param bool $notify_setting_self
161
	 * @param bool $notify_setting_selfemail
162
	 * @return DataResponse
163
	 */
164
	public function admin(
165
			$notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
166
			$notify_setting_self = false,
167
			$notify_setting_selfemail = false) {
168
169
		$settings = $this->manager->getSettings();
170 View Code Duplication
		foreach ($settings as $setting) {
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...
171
			if ($setting->canChangeStream()) {
172
				$this->config->setAppValue(
173
					'activity',
174
					'notify_stream_' . $setting->getIdentifier(),
175
					(int) $this->request->getParam($setting->getIdentifier() . '_stream', false)
176
				);
177
			}
178
179
			if ($setting->canChangeMail()) {
180
				$this->config->setAppValue(
181
					'activity',
182
					'notify_email_' . $setting->getIdentifier(),
183
					(int) $this->request->getParam($setting->getIdentifier() . '_email', false)
184
				);
185
			}
186
		}
187
188
		$email_batch_time = 3600;
189 View Code Duplication
		if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
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...
190
			$email_batch_time = 3600 * 24;
191
		} else if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
192
			$email_batch_time = 3600 * 24 * 7;
193
		} else if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_ASAP) {
194
			$email_batch_time = 0;
195
		}
196
197
		$this->config->setAppValue(
198
			'activity',
199
			'notify_setting_batchtime',
200
			$email_batch_time
201
		);
202
		$this->config->setAppValue(
203
			'activity',
204
			'notify_setting_self',
205
			(int) $notify_setting_self
206
		);
207
		$this->config->setAppValue(
208
			'activity',
209
			'notify_setting_selfemail',
210
			(int) $notify_setting_selfemail
211
		);
212
213
		return new DataResponse(array(
214
			'data'		=> array(
215
				'message'	=> (string) $this->l10n->t('Settings have been updated.'),
216
			),
217
		));
218
	}
219
220
	/**
221
	 * @NoAdminRequired
222
	 *
223
	 * @param string $enable	'true' if the feed is enabled
224
	 * @return DataResponse
225
	 */
226
	public function feed($enable) {
227
		$token = $tokenUrl = '';
228
229
		if ($enable === 'true') {
230
			$conflicts = true;
231
232
			// Check for collisions
233
			while (!empty($conflicts)) {
234
				$token = $this->random->generate(30, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
235
				$conflicts = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
236
			}
237
238
			$tokenUrl = $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $token]);
239
		}
240
241
		$this->config->setUserValue($this->user, 'activity', 'rsstoken', $token);
242
243
		return new DataResponse(array(
244
			'data'		=> array(
245
				'message'	=> (string) $this->l10n->t('Your settings have been updated.'),
246
				'rsslink'	=> $tokenUrl,
247
			),
248
		));
249
	}
250
}
251