Issues (1798)

Security Analysis    not enabled

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.

apps/files_sharing/lib/Hooks.php (1 issue)

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 Björn Schießle <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Lukas Reschke <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Robin Appelman <[email protected]>
8
 *
9
 * @copyright Copyright (c) 2018, ownCloud GmbH
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\Files_Sharing;
27
28
use OC\Files\Filesystem;
29
use OCA\FederatedFileSharing\DiscoveryManager;
30
use OCP\IURLGenerator;
31
use OCP\Files\IRootFolder;
32
use Symfony\Component\EventDispatcher\EventDispatcher;
33
use OCP\Share\IShare;
34
use Symfony\Component\EventDispatcher\GenericEvent;
35
use OCA\Files_Sharing\Service\NotificationPublisher;
36
use OCP\Share\Exceptions\ShareNotFound;
37
38
class Hooks {
39
	/**
40
	 * @var IURLGenerator
41
	 */
42
	private $urlGenerator;
43
44
	/**
45
	 * @var IRootFolder
46
	 */
47
	private $rootFolder;
48
49
	/**
50
	 * @var EventDispatcher
51
	 */
52
	private $eventDispatcher;
53
54
	/**
55
	 * @var \OCP\Share\IManager
56
	 */
57
	private $shareManager;
58
59
	/**
60
	 * @var NotificationPublisher
61
	 */
62
	private $notificationPublisher;
63
64
	public function __construct(
65
		IRootFolder $rootFolder,
66
		IUrlGenerator $urlGenerator,
67
		EventDispatcher $eventDispatcher,
68
		\OCP\Share\IManager $shareManager,
69
		NotificationPublisher $notificationPublisher
70
	) {
71
		$this->rootFolder = $rootFolder;
72
		$this->urlGenerator = $urlGenerator;
73
		$this->eventDispatcher = $eventDispatcher;
74
		$this->shareManager = $shareManager;
75
		$this->notificationPublisher = $notificationPublisher;
76
	}
77
78
	public static function deleteUser($params) {
79
		$discoveryManager = new DiscoveryManager(
80
			\OC::$server->getMemCacheFactory(),
81
			\OC::$server->getHTTPClientService()
82
		);
83
		$manager = new External\Manager(
84
			\OC::$server->getDatabaseConnection(),
85
			\OC\Files\Filesystem::getMountManager(),
86
			\OC\Files\Filesystem::getLoader(),
87
			\OC::$server->getNotificationManager(),
88
			\OC::$server->getEventDispatcher(),
89
			$params['uid']);
90
91
		$manager->removeUserShares($params['uid']);
92
	}
93
94
	public static function unshareChildren($params) {
95
		$path = Filesystem::getView()->getAbsolutePath($params['path']);
96
		$view = new \OC\Files\View('/');
97
98
		// find share mount points within $path and unmount them
99
		$mountManager = \OC\Files\Filesystem::getMountManager();
100
		$mountedShares = $mountManager->findIn($path);
101
		foreach ($mountedShares as $mount) {
102
			if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) {
103
				$mountPoint = $mount->getMountPoint();
104
				$view->unlink($mountPoint);
105
			}
106
		}
107
	}
108
109
	public function registerListeners() {
110
		$this->eventDispatcher->addListener(
111
			'files.resolvePrivateLink',
112 View Code Duplication
			function (GenericEvent $event) {
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...
113
				$uid = $event->getArgument('uid');
114
				$fileId = $event->getArgument('fileid');
115
116
				$link = $this->resolvePrivateLink($uid, $fileId);
117
118
				if ($link !== null) {
119
					$event->setArgument('resolvedWebLink', $link);
120
				}
121
			}
122
		);
123
124
		$this->eventDispatcher->addListener(
125
			'share.afterCreate',
126
			function (GenericEvent $event) {
127
				$shareObject = $event->getArgument('shareObject');
128
				$this->notificationPublisher->sendNotification($shareObject);
129
			}
130
		);
131
132
		$this->eventDispatcher->addListener(
133
			'share.afterDelete',
134
			function (GenericEvent $event) {
135
				$shareObject = $event->getArgument('shareObject');
136
				$this->notificationPublisher->discardNotification($shareObject);
137
			}
138
		);
139
	}
140
141
	private function filterSharesByFileId($shares, $fileId) {
142
		return \array_filter($shares, function (IShare $share) use ($fileId) {
143
			return \strval($share->getNodeId()) === \strval($fileId);
144
		});
145
	}
146
147
	/**
148
	 * Resolves web URL that points to the "shared with you" view of the given file
149
	 *
150
	 * @param string $uid user id
151
	 * @param string $fileId file id
152
	 * @return string|null view URL or null if the file is not found or not accessible
153
	 */
154
	private function resolvePrivateLink($uid, $fileId) {
155
		// this is only here to verify that there is indeed such share
156
		$shares = $this->filterSharesByFileId($this->shareManager->getSharedWith($uid, \OCP\Share::SHARE_TYPE_USER), $fileId);
157
		if (empty($shares)) {
158
			$shares = $this->filterSharesByFileId($this->shareManager->getSharedWith($uid, \OCP\Share::SHARE_TYPE_GROUP), $fileId);
159
		}
160
161
		// if share exists, redirect to view
162
		if (!empty($shares)) {
163
			$params['view'] = 'sharingin';
164
			// scroll to the entry
165
			$params['scrollto'] = $fileId;
166
			return $this->urlGenerator->linkToRoute('files.view.index', $params);
167
		}
168
169
		return null;
170
	}
171
}
172