Issues (21)

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/BackgroundJob.php (6 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
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016, Joas Schilling <[email protected]>
5
 *
6
 * @author Joas Schilling <[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\AnnouncementCenter;
26
27
use OC\BackgroundJob\QueuedJob;
28
use OCA\AnnouncementCenter\Model\Announcement;
29
use OCA\AnnouncementCenter\Model\AnnouncementDoesNotExistException;
30
use OCA\Guests\UserBackend;
31
use OCP\Activity\IEvent;
32
use OCP\Activity\IManager as IActivityManager;
33
use OCP\IConfig;
34
use OCP\IGroup;
35
use OCP\IGroupManager;
36
use OCP\IUser;
37
use OCP\IUserManager;
38
use OCP\Notification\IManager as INotificationManager;
39
use OCP\Notification\INotification;
40
41
class BackgroundJob extends QueuedJob {
42
	/** @var IConfig */
43
	protected $config;
44
	/** @var INotificationManager */
45
	protected $notificationManager;
46
47
	/** @var IUserManager */
48
	private $userManager;
49
50
	/** @var IGroupManager */
51
	private $groupManager;
52
53
	/** @var Manager */
54
	private $manager;
55
56
	/** @var IActivityManager */
57
	private $activityManager;
58
59
	/** @var array */
60
	protected $notifiedUsers = [];
61
62
	/** @var bool */
63
	protected $enabledForGuestsUsers;
64
65 11 View Code Duplication
	public function __construct(
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...
66
		IConfig $config,
67
		IUserManager $userManager,
68
		IGroupManager $groupManager,
69
		IActivityManager $activityManager,
70
		INotificationManager $notificationManager,
71
		Manager $manager) {
72 11
		$this->config = $config;
73 11
		$this->userManager = $userManager;
74 11
		$this->groupManager = $groupManager;
75 11
		$this->activityManager = $activityManager;
76 11
		$this->notificationManager = $notificationManager;
77 11
		$this->manager = $manager;
78 11
	}
79
80
	/**
81
	 * @param array $arguments
82
	 */
83 4
	public function run($arguments) {
84
		try {
85 4
			$announcement = $this->manager->getAnnouncement($arguments['id'], true);
86 1
		} catch (AnnouncementDoesNotExistException $e) {
87
			// Announcement was deleted in the meantime, so no need to announce it anymore
88
			// So we die silently
89 1
			return;
90
		}
91
92 3
		$guestsWhiteList = $this->config->getAppValue('guests', 'whitelist', null);
93 3
		$this->enabledForGuestsUsers = $guestsWhiteList !== null && strpos($guestsWhiteList, 'announcementcenter') !== false;
94
95 3
		$this->createPublicity($announcement, $arguments);
96 3
	}
97
98
	/**
99
	 * @param Announcement $announcement
100
	 * @param array $publicity
101
	 */
102 2
	protected function createPublicity(Announcement $announcement, array $publicity): void {
103 2
		$event = $this->activityManager->generateEvent();
104 2
		$event->setApp('announcementcenter')
105 2
			->setType('announcementcenter')
106 2
			->setAuthor($announcement->getUser())
107 2
			->setTimestamp($announcement->getTime())
108 2
			->setSubject('announcementsubject', ['author' => $announcement->getUser(), 'announcement' => $announcement->getId()])
109 2
			->setMessage('announcementmessage')
110 2
			->setObject('announcement', $announcement->getId());
111
112 2
		$dateTime = new \DateTime();
113 2
		$dateTime->setTimestamp($announcement->getTime());
114
115 2
		$notification = $this->notificationManager->createNotification();
116 2
		$notification->setApp('announcementcenter')
117 2
			->setDateTime($dateTime)
118 2
			->setObject('announcement', (string)$announcement->getId())
119 2
			->setSubject('announced', [$announcement->getUser()]);
120
121 2
		$groups = $this->manager->getGroups($announcement);
122 2
		if (\in_array('everyone', $groups, true)) {
123 1
			$this->createPublicityEveryone($announcement->getUser(), $event, $notification, $publicity);
124
		} else {
125 1
			$this->createPublicityGroups($announcement->getUser(), $event, $notification, $groups, $publicity);
126
		}
127 2
	}
128
129
	/**
130
	 * @param string $authorId
131
	 * @param IEvent $event
132
	 * @param INotification $notification
133
	 * @param array $publicity
134
	 */
135 2
	protected function createPublicityEveryone(string $authorId, IEvent $event, INotification $notification, array $publicity) {
136
		$this->userManager->callForSeenUsers(function(IUser $user) use ($authorId, $event, $notification, $publicity) {
137 2
			if (!$this->enabledForGuestsUsers && $user->getBackend() instanceof UserBackend) {
0 ignored issues
show
The class OCA\Guests\UserBackend does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
138
				return;
139
			}
140
141 2
			if (!empty($publicity['activities'])) {
142 1
				$event->setAffectedUser($user->getUID());
143 1
				$this->activityManager->publish($event);
144
			}
145
146 2 View Code Duplication
			if (!empty($publicity['notifications']) && $authorId !== $user->getUID()) {
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...
147 1
				$notification->setUser($user->getUID());
148 1
				$this->notificationManager->notify($notification);
149
			}
150 2
		});
151 2
	}
152
153
	/**
154
	 * @param string $authorId
155
	 * @param IEvent $event
156
	 * @param INotification $notification
157
	 * @param string[] $groups
158
	 * @param array $publicity
159
	 */
160 2
	protected function createPublicityGroups($authorId, IEvent $event, INotification $notification, array $groups, array $publicity) {
161 2
		foreach ($groups as $gid) {
162 2
			$group = $this->groupManager->get($gid);
163 2
			if (!($group instanceof IGroup)) {
0 ignored issues
show
The class OCP\IGroup does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
164 2
				continue;
165
			}
166
167 2
			$users = $group->getUsers();
168 2
			foreach ($users as $user) {
169 2
				if (!$this->enabledForGuestsUsers && $user->getBackend() instanceof UserBackend) {
0 ignored issues
show
The class OCA\Guests\UserBackend does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
170
					continue;
171
				}
172
173 2
				$uid = $user->getUID();
174 2
				if (isset($this->notifiedUsers[$uid]) || $user->getLastLogin() === 0) {
175 2
					continue;
176
				}
177
178 2
				if (!empty($publicity['activities'])) {
179 1
					$event->setAffectedUser($uid);
180 1
					$this->activityManager->publish($event);
181
				}
182
183 2 View Code Duplication
				if ($authorId !== $uid && !empty($publicity['notifications'])) {
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...
184 1
					$notification->setUser($uid);
185 1
					$this->notificationManager->notify($notification);
186
				}
187
188 2
				$this->notifiedUsers[$uid] = true;
189
			}
190
		}
191 2
	}
192
}
193