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.

dav/appinfo/Migrations/Version20170202213905.php (2 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
 * @author Viktar Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\DAV\Migrations;
23
24
use OCP\DB\QueryBuilder\IQueryBuilder;
25
use OCP\Files\Node;
26
use OCP\IDBConnection;
27
use OCP\IUser;
28
use OCP\IUserManager;
29
use OCP\Migration\ISqlMigration;
30
31
/*
32
 * Resolve userid/propertypath into fileid
33
 * Update all entries with actual fileid if possible
34
 * Drop all entries that can't be resolved
35
 */
36
class Version20170202213905 implements ISqlMigration {
37
38
	/** @var IUserManager */
39
	private $userManager;
40
41
	/** @var string[]  */
42
	private $statements = [];
43
44
	public function __construct(IUserManager $userManager) {
45
		$this->userManager = $userManager;
46
	}
47
48
	/**
49
	 * @param IDBConnection $connection
50
	 * @return array
51
	 */
52
	public function sql(IDBConnection $connection) {
53
		$qb = $connection->getQueryBuilder();
54
		$qb->select('*')
55
			->from('properties', 'props')
56
			->setMaxResults(1);
57
		$result = $qb->execute();
58
		$row = $result->fetch();
59
60
		// There is nothing to do if table is empty or has no userid field
61
		if (!$row || !isset($row['userid'])) {
62
			return $this->statements;
63
		}
64
65
		$qb->resetQueryParts()
66
			->setMaxResults(null)
67
			->select('userid', 'propertypath')
0 ignored issues
show
The call to IQueryBuilder::select() has too many arguments starting with 'propertypath'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
			->from('properties', 'props')
69
			->groupBy('userid')
70
			->addGroupBy('propertypath')
71
			->orderBy('userid')
72
			->addOrderBy('propertypath');
73
74
		$selectResult = $qb->execute();
75
		while ($row = $selectResult->fetch()) {
76
			try {
77
				$sql = $this->getRepairEntrySql($qb, $row);
78
				if ($sql !== null) {
79
					$this->statements[] = $sql;
80
				}
81
			} catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
82
			}
83
		}
84
85
		//Mounted FS can have side effects on further migrations
86
		\OC_Util::tearDownFS();
87
88
		// drop entries with empty fileid
89
		$dropQuery = $qb->resetQueryParts()
90
			->delete('properties')
91
			->where(
92
				$qb->expr()->eq('fileid', $qb->expr()->literal('0'))
93
			)
94
			->orWhere(
95
				$qb->expr()->isNull('fileid')
96
			);
97
		$this->statements[] = $dropQuery->getSQL();
98
99
		return $this->statements;
100
	}
101
102
	/**
103
	 * @param IQueryBuilder $qb
104
	 * @param $entry
105
	 * @return string|null
106
	 */
107
	private function getRepairEntrySql(IQueryBuilder $qb, $entry) {
108
		$userId = $entry['userid'];
109
		$user = $this->userManager->get($userId);
110
		if (!($user instanceof IUser)) {
111
			return null;
112
		}
113
114
		$node = \OC::$server->getUserFolder($userId)->get($entry['propertypath']);
115
		if ($node instanceof Node && $node->getId()) {
116
			$fileId = $node->getId();
117
			$updateQuery = $this->getRepairQuery($qb, $fileId, $userId, $entry['propertypath']);
118
			return $updateQuery->getSQL();
119
		}
120
		return null;
121
	}
122
123
	/**
124
	 * @param IQueryBuilder $qb
125
	 * @param int $fileId
126
	 * @param string $userId
127
	 * @param string $propertyPath
128
	 * @return IQueryBuilder
129
	 */
130
	private function getRepairQuery(IQueryBuilder $qb, $fileId, $userId, $propertyPath) {
131
		return $qb->resetQueryParts()
132
			->update('properties')
133
			->set(
134
				'fileid',
135
				$qb->expr()->literal($fileId)
136
			)
137
			->where(
138
				$qb->expr()->eq('userid', $qb->expr()->literal($userId))
139
			)
140
			->andWhere(
141
				$qb->expr()->eq(
142
					'propertypath',
143
					$qb->expr()->literal($propertyPath)
144
				)
145
			);
146
	}
147
}
148