Issues (108)

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.

service/searchfolderservice.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
 * Gallery
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Olivier Paroz <[email protected]>
9
 *
10
 * @copyright Olivier Paroz 2014-2016
11
 */
12
13
namespace OCA\Gallery\Service;
14
15
use OCP\Files\Folder;
16
17
use OCA\Gallery\Environment\NotFoundEnvException;
18
19
/**
20
 * Looks for the folder to use, based on the request made by the client
21
 *
22
 * This is to make sure we were not:
23
 *    * given a file
24
 *    * given a folder name with a typo
25
 *
26
 * @package OCA\Gallery\Service
27
 */
28
class SearchFolderService extends FilesService {
29
	/**
30
	 * @var int
31
	 */
32
	protected $virtualRootLevel = null;
33
34
	/**
35
	 * This returns what we think is the current folder node based on a given path
36
	 *
37
	 * @param string $location
38
	 * @param string[] $features
39
	 *
40
	 * @return array <string,Folder,bool>
41
	 */
42
	public function getCurrentFolder($location, $features) {
43
		$this->features = $features;
44
45
		return $this->findFolder($location);
46
	}
47
48
	/**
49
	 * This returns the current folder node based on a path
50
	 *
51
	 * If the path leads to a file, we'll return the node of the containing folder
52
	 *
53
	 * If we can't find anything, we try with the parent folder, up to the root or until we reach
54
	 * our recursive limit
55
	 *
56
	 * @param string $location
57
	 * @param int $depth
58
	 *
59
	 * @return array <string,Folder,bool>
60
	 */
61
	private function findFolder($location, $depth = 0) {
62
		$node = null;
63
		$location = $this->validateLocation($location, $depth);
64
		try {
65
			$node = $this->environment->getNodeFromVirtualRoot($location);
66
			if ($node->getType() === 'file') {
67
				$node = $node->getParent();
68
			}
69
		} catch (NotFoundEnvException $exception) {
70
			// There might be a typo in the file or folder name
71
			$folder = \pathinfo($location, PATHINFO_DIRNAME);
72
			$depth++;
73
74
			return $this->findFolder($folder, $depth);
75
		}
76
		$path = $this->environment->getPathFromVirtualRoot($node);
77
78
		return $this->sendFolder($path, $node);
79
	}
80
81
	/**
82
	 * Makes sure we don't go too far up before giving up
83
	 *
84
	 * @param string $location
85
	 * @param int $depth
86
	 *
87
	 * @return string
88
	 */
89
	private function validateLocation($location, $depth) {
90
		if ($depth === 4) {
91
			// We can't find anything, so we decide to return data for the root folder
92
			$location = '';
93
		}
94
95
		return $location;
96
	}
97
98
	/**
99
	 * Makes sure that the folder is not empty, does meet our requirements in terms of location and
100
	 * returns details about it
101
	 *
102
	 * @param string $path
103
	 * @param Folder $node
104
	 *
105
	 * @return array <string,Folder,bool>
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string|Folder>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
106
	 * @throws ForbiddenServiceException|NotFoundServiceException
107
	 */
108
	private function sendFolder($path, $node) {
109
		if ($node === null) {
110
			// Something very wrong has just happened
111
			throw new NotFoundServiceException('Oh Nooooes!');
112
		} elseif (!$this->isAllowedAndAvailable($node)) {
113
			throw new ForbiddenServiceException(
114
				'The owner has placed a restriction or the storage location is unavailable'
115
			);
116
		}
117
118
		return [$path, $node];
119
	}
120
}
121