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/Notification/Notifier.php (1 issue)

Labels
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
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\Notification;
26
27
28
use OCA\AnnouncementCenter\Manager;
29
use OCA\AnnouncementCenter\Model\AnnouncementDoesNotExistException;
30
use OCP\IURLGenerator;
31
use OCP\IUser;
32
use OCP\IUserManager;
33
use OCP\L10N\IFactory;
34
use OCP\Notification\AlreadyProcessedException;
35
use OCP\Notification\IManager as INotificationManager;
36
use OCP\Notification\INotification;
37
use OCP\Notification\INotifier;
38
39
class Notifier implements INotifier {
40
41
	/** @var Manager */
42
	protected $manager;
43
44
	/** @var IFactory */
45
	protected $l10nFactory;
46
47
	/** @var INotificationManager */
48
	protected $notificationManager;
49
50
	/** @var IUserManager */
51
	protected $userManager;
52
53
	/** @var IURLGenerator */
54
	protected $urlGenerator;
55
56 3
	public function __construct(Manager $manager,
57
								IFactory $l10nFactory,
58
								INotificationManager $notificationManager,
59
								IUserManager $userManager,
60
								IURLGenerator $urlGenerator) {
61 3
		$this->manager = $manager;
62 3
		$this->l10nFactory = $l10nFactory;
63 3
		$this->notificationManager = $notificationManager;
64 3
		$this->userManager = $userManager;
65 3
		$this->urlGenerator = $urlGenerator;
66 3
	}
67
68
	/**
69
	 * Identifier of the notifier, only use [a-z0-9_]
70
	 *
71
	 * @return string
72
	 * @since 17.0.0
73
	 */
74
	public function getID(): string {
75
		return 'announcementcenter';
76
	}
77
78
	/**
79
	 * Human readable name describing the notifier
80
	 *
81
	 * @return string
82
	 * @since 17.0.0
83
	 */
84
	public function getName(): string {
85
		return $this->l10nFactory->get('announcementcenter')->t('Announcements');
86
	}
87
88
	/**
89
	 * @param INotification $notification
90
	 * @param string $languageCode The code of the language that should be used to prepare the notification
91
	 * @return INotification
92
	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
93
	 */
94 2
	public function prepare(INotification $notification, string $languageCode): INotification {
95 2
		if ($notification->getApp() !== 'announcementcenter') {
96
			// Not my app => throw
97 1
			throw new \InvalidArgumentException('Unknown app');
98
		}
99
100
		// Read the language from the notification
101 1
		$l = $this->l10nFactory->get('announcementcenter', $languageCode);
102
103 1
		$i = $notification->getSubject();
104 1
		if ($i !== 'announced') {
105
			// Unknown subject => Unknown notification => throw
106 1
			throw new \InvalidArgumentException('Unknown subject');
107
		}
108
109
		try {
110
			$announcement = $this->manager->getAnnouncement((int)$notification->getObjectId());
111
		} catch (AnnouncementDoesNotExistException $e) {
112
			throw new AlreadyProcessedException();
113
		}
114
115
		$params = $notification->getSubjectParameters();
116
		$user = $this->userManager->get($params[0]);
117
		if ($user instanceof IUser) {
0 ignored issues
show
The class OCP\IUser 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...
118
			$displayName = $user->getDisplayName();
119
		} else {
120
			$displayName = $params[0];
121
		}
122
123
		$link = $this->urlGenerator->linkToRouteAbsolute('announcementcenter.page.index', [
124
			'announcement' => $notification->getObjectId(),
125
		]);
126
127
		if ($announcement->getMessage() !== '') {
128
			$notification->setParsedMessage($announcement->getMessage());
129
		}
130
		$notification->setRichSubject(
131
				$l->t('{user} announced “{announcement}”'),
132
				[
133
					'user' => [
134
						'type' => 'user',
135
						'id' => $params[0],
136
						'name' => $displayName,
137
					],
138
					'announcement' => [
139
						'type' => 'announcement',
140
						'id' => $notification->getObjectId(),
141
						'name' => $announcement->getSubject(),
142
						'link' => $link,
143
					],
144
				]
145
			)
146
			->setLink($link)
147
			->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('announcementcenter', 'announcementcenter-dark.svg')));
148
149
		$placeholders = $replacements = [];
150
		foreach ($notification->getRichSubjectParameters() as $placeholder => $parameter) {
151
			$placeholders[] = '{' . $placeholder . '}';
152
			$replacements[] = $parameter['name'];
153
		}
154
155
		$notification->setParsedSubject(str_replace($placeholders, $replacements, $notification->getRichSubject()));
156
157
		return $notification;
158
	}
159
}
160