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/Controller/OCSController.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) 2018, Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[email protected]>
6
 * @author John Molakvoæ <[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
namespace OCA\Richdocuments\Controller;
25
26
use OCA\Richdocuments\Db\DirectMapper;
27
use OCA\Richdocuments\Service\FederationService;
28
use OCA\Richdocuments\TemplateManager;
29
use OCP\AppFramework\Http\DataResponse;
30
use OCP\AppFramework\OCS\OCSBadRequestException;
31
use OCP\AppFramework\OCS\OCSNotFoundException;
32
use OCP\Files\File;
33
use OCP\Files\Folder;
34
use OCP\Files\IRootFolder;
35
use OCP\Files\NotFoundException;
36
use OCP\IRequest;
37
use OCP\IURLGenerator;
38
39
class OCSController extends \OCP\AppFramework\OCSController {
40
41
	/** @var IRootFolder */
42
	private $rootFolder;
43
44
	/** @var string */
45
	private $userId;
46
47
	/** @var DirectMapper */
48
	private $directMapper;
49
50
	/** @var IURLGenerator */
51
	private $urlGenerator;
52
53
	/** @var TemplateManager */
54
	private $manager;
55
56
	/** @var FederationService */
57
	private $federationService;
58
59
	/**
60
	 * OCS controller
61
	 *
62
	 * @param string $appName
63
	 * @param IRequest $request
64
	 * @param IRootFolder $rootFolder
65
	 * @param string $userId
66
	 * @param DirectMapper $directMapper
67
	 * @param IURLGenerator $urlGenerator
68
	 * @param TemplateManager $manager
69
	 */
70 View Code Duplication
	public function __construct(string $appName,
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...
71
		IRequest $request,
72
		IRootFolder $rootFolder,
73
		$userId,
74
		DirectMapper $directMapper,
75
		IURLGenerator $urlGenerator,
76
		TemplateManager $manager,
77
		FederationService $federationService
78
	) {
79
		parent::__construct($appName, $request);
80
81
		$this->rootFolder   = $rootFolder;
82
		$this->userId       = $userId;
83
		$this->directMapper = $directMapper;
84
		$this->urlGenerator = $urlGenerator;
85
		$this->manager      = $manager;
86
		$this->federationService = $federationService;
87
	}
88
89
	/**
90
	 * @NoAdminRequired
91
	 *
92
	 * Init an editing session
93
	 *
94
	 * @param int $fileId
95
	 * @return DataResponse
96
	 * @throws OCSNotFoundException|OCSBadRequestException
97
	 */
98
	public function create($fileId) {
99
		try {
100
			$userFolder = $this->rootFolder->getUserFolder($this->userId);
101
			$nodes      = $userFolder->getById($fileId);
102
103
			if ($nodes === []) {
104
				throw new OCSNotFoundException();
105
			}
106
107
			$node = $nodes[0];
108
			if ($node instanceof Folder) {
109
				throw new OCSBadRequestException('Cannot view folder');
110
			}
111
112
			$direct = $this->directMapper->newDirect($this->userId, $fileId);
113
114
			return new DataResponse([
115
				'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [
116
					'token' => $direct->getToken()
117
				])
118
			]);
119
		} catch (NotFoundException $e) {
120
			throw new OCSNotFoundException();
121
		}
122
	}
123
124
	/**
125
	 * @NoAdminRequired
126
	 *
127
	 * @param string $type The template type
128
	 * @return DataResponse
129
	 * @throws OCSBadRequestException
130
	 */
131
	public function getTemplates($type) {
132
		if (array_key_exists($type, TemplateManager::$tplTypes)) {
133
			$templates = $this->manager->getAllFormatted($type);
134
			return new DataResponse($templates);
135
		}
136
		throw new OCSBadRequestException('Wrong type');
137
	}
138
139
	/**
140
	 * @NoAdminRequired
141
	 *
142
	 * @param string $path Where to create the document
143
	 * @param int $template The template id
144
	 */
145
	public function createFromTemplate($path, $template) {
146
		if ($path === null || $template === null) {
147
			throw new OCSBadRequestException('path and template must be set');
148
		}
149
150
		if (!$this->manager->isTemplate($template)) {
151
			throw new OCSBadRequestException('Invalid template provided');
152
		}
153
154
		$info = $this->mb_pathinfo($path);
155
156
		$userFolder = $this->rootFolder->getUserFolder($this->userId);
157
		$folder = $userFolder->get($info['dirname']);
158
		$name = $folder->getNonExistingName($info['basename']);
0 ignored issues
show
The method getNonExistingName() does not seem to exist on object<OCP\Files\Node>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
159
		$file = $folder->newFile($name);
0 ignored issues
show
The method newFile() does not seem to exist on object<OCP\Files\Node>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
161
		try {
162
			$direct = $this->directMapper->newDirect($this->userId, $template, $file->getId());
163
164
			return new DataResponse([
165
				'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [
166
					'token' => $direct->getToken()
167
				])
168
			]);
169
		} catch (NotFoundException $e) {
170
			throw new OCSNotFoundException();
171
		}
172
	}
173
174
	private function mb_pathinfo($filepath) {
175
		$result = [];
176
		preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', ltrim('/' . $filepath), $matches);
177
		if($matches[1]) {
178
			$result['dirname'] = $matches[1];
179
		}
180
		if($matches[2]) {
181
			$result['basename'] = $matches[2];
182
		}
183
		if($matches[5]) {
184
			$result['extension'] = $matches[5];
185
		}
186
		if($matches[3]) {
187
			$result['filename'] = $matches[3];
188
		}
189
		return $result;
190
	}
191
}
192