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/AssetsController.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
 * @copyright Copyright (c) 2018, 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\Controller;
25
26
use OCA\Richdocuments\Db\AssetMapper;
27
use OCA\Richdocuments\Service\UserScopeService;
28
use OCP\AppFramework\Controller;
29
use OCP\AppFramework\Db\DoesNotExistException;
30
use OCP\AppFramework\Http;
31
use OCP\AppFramework\Http\DataResponse;
32
use OCP\AppFramework\Http\FileDisplayResponse;
33
use OCP\AppFramework\Http\JSONResponse;
34
use OCP\Files\File;
35
use OCP\Files\IRootFolder;
36
use OCP\Files\NotFoundException;
37
use OCP\IRequest;
38
use OCP\IURLGenerator;
39
40
class AssetsController extends Controller {
41
42
	/** @var AssetMapper */
43
	private $assetMapper;
44
45
	/** @var IRootFolder */
46
	private $rootFolder;
47
48
	/** @var string */
49
	private $userId;
50
51
	/** @var IURLGenerator */
52
	private $urlGenerator;
53
54
	public function __construct($appName,
55
								IRequest $request,
56
								AssetMapper $assetMapper,
57
								IRootFolder $rootFolder,
58
								$userId,
59
								UserScopeService $userScopeService,
60
								IURLGenerator $urlGenerator) {
61
		parent::__construct($appName, $request);
62
63
		$this->assetMapper = $assetMapper;
64
		$this->rootFolder = $rootFolder;
65
		$this->userId = $userId;
66
		$this->userScopeService = $userScopeService;
67
		$this->urlGenerator = $urlGenerator;
68
	}
69
70
	/**
71
	 * @NoAdminRequired
72
	 * @NoCSRFRequired
73
	 *
74
	 * @param string $path
75
	 * @return JSONResponse
76
	 */
77
	public function create($path) {
78
		$userFolder = $this->rootFolder->getUserFolder($this->userId);
79
80
		try {
81
			$node = $userFolder->get($path);
82
		} catch (NotFoundException $e) {
83
			return new JSONResponse([], Http::STATUS_NOT_FOUND);
84
		}
85
86
		$asset = $this->assetMapper->newAsset($this->userId, $node->getId());
87
88
		return new JSONResponse([
89
			'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.assets.get', [
90
				'token' => $asset->getToken(),
91
			])
92
		]);
93
	}
94
95
	/**
96
	 * @PublicPage
97
	 * @NoCSRFRequired
98
	 *
99
	 * @param string $token
100
	 * @return Http\Response
101
	 */
102
	public function get($token) {
103
		try {
104
			$asset = $this->assetMapper->getAssetByToken($token);
105
		} catch (DoesNotExistException $e) {
106
			return new DataResponse([], Http::STATUS_NOT_FOUND);
107
		}
108
109
		// Do not clear the asset on HEAD requests
110
		if ($this->request->getMethod() === 'GET') {
111
			// Clear the assets so we can only fetch it once
112
			$this->assetMapper->delete($asset);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
113
		}
114
115
116
		$this->userScopeService->setUserScope($asset->getUid());
117
		$userFolder = $this->rootFolder->getUserFolder($asset->getUid());
118
		$nodes = $userFolder->getById($asset->getFileid());
119
120
		if ($nodes === []) {
121
			return new DataResponse([], Http::STATUS_NOT_FOUND);
122
		}
123
124
		$node = array_pop($nodes);
125
		if (!($node instanceof File)) {
126
			return new DataResponse([], Http::STATUS_NOT_FOUND);
127
		}
128
129
		return new FileDisplayResponse($node, Http::STATUS_OK, [
130
			'Content-Type' => $node->getMimeType()
131
		]);
132
	}
133
}
134