Issues (213)

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.

lib/Service/CapabilitiesService.php (3 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) 2019, Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
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
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Richdocuments\Service;
25
26
use OCP\App\IAppManager;
27
use OCP\Http\Client\IClientService;
28
use OCP\ICache;
29
use OCP\ICacheFactory;
30
use OCP\IConfig;
31
32
class CapabilitiesService {
33
34
	/** @var IConfig */
35
	private $config;
36
	/** @var IClientService */
37
	private $clientService;
38
	/** @var ICache */
39
	private $cache;
40
	/** @var IAppManager */
41
	private $appManager;
42
43
	/** @var array */
44
	private $capabilities;
45
46
47 View Code Duplication
	public function __construct(IConfig $config, IClientService $clientService, ICacheFactory $cacheFactory, IAppManager $appManager) {
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...
48
		$this->config = $config;
49
		$this->clientService = $clientService;
50
		$this->cache = $cacheFactory->createDistributed('richdocuments');
51
		$this->appManager = $appManager;
52
	}
53
54
	public function getCapabilities() {
55
		if (!$this->capabilities) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->capabilities of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56
			$this->capabilities = $this->cache->get('capabilities');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->cache->get('capabilities') of type * is incompatible with the declared type array of property $capabilities.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
		}
58
59
		$isARM64 = php_uname('m') === 'aarch64';
60
		$CODEAppID = $isARM64 ? 'richdocumentscode_arm64' : 'richdocumentscode';
61
		$isCODEInstalled = $this->appManager->isEnabledForUser($CODEAppID);
62
		$isCODEEnabled = strpos($this->config->getAppValue('richdocuments', 'wopi_url'), 'proxy.php?req=') !== false;
63
		$shouldRecheckCODECapabilities = $isCODEInstalled && $isCODEEnabled && ($this->capabilities === null || count($this->capabilities) === 0);
64
		if($this->capabilities === null || $shouldRecheckCODECapabilities) {
65
			$this->refetch();
66
		}
67
68
		if (!is_array($this->capabilities)) {
69
			return [];
70
		}
71
72
		return $this->capabilities;
73
	}
74
75
	public function hasTemplateSaveAs() {
76
		return $this->getCapabilities()['hasTemplateSaveAs'] ?? false;
77
	}
78
79
	public function hasTemplateSource() {
80
		return $this->getCapabilities()['hasTemplateSource'] ?? false;
81
	}
82
83
	public function clear() {
84
		$this->cache->remove('capabilities');
85
	}
86
87
	public function refetch() {
88
		$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
89
		if ($remoteHost === '') {
90
			return [];
91
		}
92
		$capabilitiesEndpoint = $remoteHost . '/hosting/capabilities';
93
94
		$client = $this->clientService->newClient();
95
		$options = ['timeout' => 45, 'nextcloud' => ['allow_local_address' => true]];
96
97
		if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') {
98
			$options['verify'] = false;
99
		}
100
101
		try {
102
			$response = $client->get($capabilitiesEndpoint, $options);
103
			$responseBody = $response->getBody();
104
			$capabilities = \json_decode($responseBody, true);
105
106
			if (!is_array($capabilities)) {
107
				$capabilities = [];
108
			}
109
110
111
		} catch (\Exception $e) {
112
			$capabilities = [];
113
		}
114
115
		$this->capabilities = $capabilities;
116
		$this->cache->set('capabilities', $capabilities, 3600);
117
	}
118
}
119