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/UserSettings.php (2 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
 *
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;
24
25
use OCP\Activity\IManager;
26
use OCP\IConfig;
27
28
/**
29
 * Class UserSettings
30
 *
31
 * @package OCA\Activity
32
 */
33
class UserSettings {
34
	/** @var IManager */
35
	protected $manager;
36
37
	/** @var IConfig */
38
	protected $config;
39
40
	/** @var Data */
41
	protected $data;
42
43
	const EMAIL_SEND_HOURLY = 0;
44
	const EMAIL_SEND_DAILY = 1;
45
	const EMAIL_SEND_WEEKLY = 2;
46
	const EMAIL_SEND_ASAP = 3;
47
48
	/**
49
	 * @param IManager $manager
50
	 * @param IConfig $config
51
	 */
52 25
	public function __construct(IManager $manager, IConfig $config) {
53 25
		$this->manager = $manager;
54 25
		$this->config = $config;
55 25
	}
56
57
	/**
58
	 * Get a setting for a user
59
	 *
60
	 * Falls back to some good default values if the user does not have a preference
61
	 *
62
	 * @param string $user
63
	 * @param string $method Should be one of 'stream', 'email' or 'setting'
64
	 * @param string $type One of the activity types, 'batchtime' or 'self'
65
	 * @return bool|int
66
	 */
67 5
	public function getUserSetting($user, $method, $type) {
68 5
		if ($method === 'email' && $this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
69
			return false;
70
		}
71
72 5
		$defaultSetting = $this->getDefaultFromSetting($method, $type);
73 5 View Code Duplication
		if (is_bool($defaultSetting)) {
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...
74 5
			return (bool) $this->config->getUserValue(
75 5
				$user,
76 5
				'activity',
77 5
				'notify_' . $method . '_' . $type,
78
				$defaultSetting
79
			);
80
		}
81
82
		return (int) $this->config->getUserValue(
83
			$user,
84
			'activity',
85
			'notify_' . $method . '_' . $type,
86
			$defaultSetting
87
		);
88
	}
89
90
	/**
91
	 * @param string $method
92
	 * @param string $type
93
	 * @return bool|int
94
	 */
95
	public function getConfigSetting($method, $type) {
96
		$defaultSetting = $this->getDefaultFromSetting($method, $type);
97 View Code Duplication
		if (is_bool($defaultSetting)) {
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...
98
			return (bool) $this->config->getAppValue(
99
				'activity',
100
				'notify_' . $method . '_' . $type,
101
				$defaultSetting
102
			);
103
		}
104
105
		return (int) $this->config->getAppValue(
106
			'activity',
107
			'notify_' . $method . '_' . $type,
108
			$defaultSetting
109
		);
110
	}
111
112
	/**
113
	 * Get a good default setting for a preference
114
	 *
115
	 * @param string $method Should be one of 'stream', 'email' or 'setting'
116
	 * @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
117
	 * @return bool|int
118
	 */
119 11
	protected function getDefaultFromSetting($method, $type) {
120 11
		if ($method === 'setting') {
121 9
			if ($type === 'batchtime') {
122 1
				return 3600;
123
			}
124
125 8
			if ($type === 'self') {
126 6
				return true;
127
			}
128
129 3
			if ($type === 'selfemail') {
130 2
				return false;
131
			}
132
133 1
			return false;
134
		}
135
136
		try {
137 7
			$setting = $this->manager->getSettingById($type);
138 7
			return ($method === 'stream') ? $setting->isDefaultEnabledStream() : $setting->isDefaultEnabledMail();
139 5
		} catch (\InvalidArgumentException $e) {
140 5
			return false;
141
		}
142
	}
143
144
	/**
145
	 * Get a list with enabled notification types for a user
146
	 *
147
	 * @param string	$user	Name of the user
148
	 * @param string	$method	Should be one of 'stream' or 'email'
149
	 * @return array
150
	 */
151 5
	public function getNotificationTypes($user, $method) {
152 5
		$notificationTypes = array();
153
154 5
		$settings = $this->manager->getSettings();
155 5
		foreach ($settings as $setting) {
156 5
			if ($this->getUserSetting($user, $method, $setting->getIdentifier())) {
157 5
				$notificationTypes[] = $setting->getIdentifier();
158
			}
159
		}
160
161 5
		return $notificationTypes;
162
	}
163
164
	/**
165
	 * Filters the given user array by their notification setting
166
	 *
167
	 * @param array $users
168
	 * @param string $method
169
	 * @param string $type
170
	 * @return array Returns a "username => b:true" Map for method = stream
171
	 *               Returns a "username => i:batchtime" Map for method = email
172
	 */
173
	public function filterUsersBySetting($users, $method, $type) {
174
		if (empty($users) || !is_array($users)) {
175
			return [];
176
		}
177
178
		if ($method === 'email' && $this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
179
			return [];
180
		}
181
182
		$filteredUsers = array();
183
		$potentialUsers = $this->config->getUserValueForUsers('activity', 'notify_' . $method . '_' . $type, $users);
184
		foreach ($potentialUsers as $user => $value) {
185
			if ($value) {
186
				$filteredUsers[$user] = true;
187
			}
188
			unset($users[array_search($user, $users, true)]);
189
		}
190
191
		// Get the batch time setting from the database
192
		if ($method === 'email') {
193
			$potentialUsers = $this->config->getUserValueForUsers('activity', 'notify_setting_batchtime', array_keys($filteredUsers));
194
			foreach ($potentialUsers as $user => $value) {
195
				$filteredUsers[$user] = $value;
196
			}
197
		}
198
199
		if (empty($users)) {
200
			return $filteredUsers;
201
		}
202
203
		// If the setting is enabled by default,
204
		// we add all users that didn't set the preference yet.
205
		if ($this->getDefaultFromSetting($method, $type)) {
206
			foreach ($users as $user) {
207
				if ($method === 'stream') {
208
					$filteredUsers[$user] = true;
209
				} else {
210
					$filteredUsers[$user] = $this->getDefaultFromSetting('setting', 'batchtime');
211
				}
212
			}
213
		}
214
215
		return $filteredUsers;
216
	}
217
}
218