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/Db/WopiMapper.php (4 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 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
namespace OCA\Richdocuments\Db;
24
25
use OCP\AppFramework\Db\DoesNotExistException;
26
use OCP\AppFramework\Db\Mapper;
27
use OCP\AppFramework\Utility\ITimeFactory;
28
use OCP\IDBConnection;
29
use OCP\ILogger;
30
use OCP\Security\ISecureRandom;
31
32
class WopiMapper extends Mapper {
0 ignored issues
show
Deprecated Code introduced by
The class OCP\AppFramework\Db\Mapper has been deprecated with message: 14.0.0 Move over to QBMapper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
33
	// Tokens expire after this many seconds (not defined by WOPI specs).
34
	const TOKEN_LIFETIME_SECONDS = 1800;
35
36
	/** @var ISecureRandom */
37
	private $random;
38
39
	/** @var ILogger */
40
	private $logger;
41
42
	/** @var ITimeFactory */
43
	private $timeFactory;
44
45
	public function __construct(IDBConnection $db,
46
								ISecureRandom $random,
47
								ILogger $logger,
48
								ITimeFactory $timeFactory) {
49
		parent::__construct($db, 'richdocuments_wopi', Wopi::class);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::__construct() 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...
50
51
		$this->random = $random;
52
		$this->logger = $logger;
53
		$this->timeFactory = $timeFactory;
54
	}
55
56
	/**
57
	 * @param int $fileId
58
	 * @param string $owner
59
	 * @param string $editor
60
	 * @param int $version
61
	 * @param bool $updatable
62
	 * @param string $serverHost
63
	 * @param string $guestDisplayname
64
	 * @param int $templateDestination
65
	 * @return Wopi
66
	 */
67
	public function generateFileToken($fileId, $owner, $editor, $version, $updatable, $serverHost, $guestDisplayname, $templateDestination = 0, $hideDownload = false, $direct = false, $isRemoteToken = false, $templateId = 0, $share = null) {
68
		$token = $this->random->generate(32, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
69
70
		$wopi = Wopi::fromParams([
71
			'fileid' => $fileId,
72
			'ownerUid' => $owner,
73
			'editorUid' => $editor,
74
			'version' => $version,
75
			'canwrite' => $updatable,
76
			'serverHost' => $serverHost,
77
			'token' => $token,
78
			'expiry' => $this->timeFactory->getTime() + self::TOKEN_LIFETIME_SECONDS,
79
			'guestDisplayname' => $guestDisplayname,
80
			'templateDestination' => $templateDestination,
81
			'hideDownload' => $hideDownload,
82
			'direct' => $direct,
83
			'isRemoteToken' => $isRemoteToken,
84
			'templateId' => $templateId,
85
			'remoteServer' => '',
86
			'remoteServerToken' => '',
87
			'share' => $share
88
		]);
89
90
		/** @var Wopi $wopi */
91
		$wopi = $this->insert($wopi);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::insert() 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...
92
93
		return $wopi;
94
	}
95
96
	/**
97
	 * @deprecated
98
	 * @param $token
99
	 */
100
	public function getPathForToken($token) {
101
		return $this->getWopiForToken($token);
102
	}
103
	/**
104
	 * Given a token, validates it and
105
	 * constructs and validates the path.
106
	 * Returns the path, if valid, else false.
107
	 *
108
	 * @param string $token
109
	 * @throws DoesNotExistException
110
	 * @return Wopi
111
	 */
112
	public function getWopiForToken($token) {
113
114
		$qb = $this->db->getQueryBuilder();
115
		$qb->select('*')
116
			->from('richdocuments_wopi')
117
			->where(
118
				$qb->expr()->eq('token', $qb->createNamedParameter($token))
119
			);
120
		$result = $qb->execute();
121
		$row = $result->fetch();
122
		$result->closeCursor();
123
124
		$this->logger->debug('Loaded WOPI Token record: {row}.', [
0 ignored issues
show
Deprecated Code introduced by
The method OCP\ILogger::debug() has been deprecated with message: 20.0.0 use \Psr\Log\LoggerInterface::debug

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...
125
			'row' => $row,
126
			'app' => 'richdocuments'
127
		]);
128
		if ($row === false) {
129
			throw new DoesNotExistException('Could not find token.');
130
		}
131
132
		/** @var Wopi $wopi */
133
		$wopi = Wopi::fromRow($row);
134
135
		//TODO: validate.
136
		if ($wopi->getExpiry() > $this->timeFactory->getTime()){
137
			// Expired token!
138
			//http_response_code(404);
139
			//$wopi->deleteBy('id', $row['id']);
140
			//return false;
141
		}
142
143
		return $wopi;
144
	}
145
}
146