Issues (61)

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.

controller/files.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
 * ownCloud - galleryplus
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
 * @author Robin Appelman <[email protected]>
10
 *
11
 * @copyright Olivier Paroz 2014-2016
12
 * @copyright Robin Appelman 2012-2014
13
 */
14
15
namespace OCA\GalleryPlus\Controller;
16
17
use OCP\Files\File;
18
use OCP\Files\Folder;
19
use OCP\ILogger;
20
21
use OCP\AppFramework\Http;
22
23
use OCA\GalleryPlus\Service\SearchFolderService;
24
use OCA\GalleryPlus\Service\ConfigService;
25
use OCA\GalleryPlus\Service\SearchMediaService;
26
use OCA\GalleryPlus\Service\DownloadService;
27
28
/**
29
 * Trait Files
30
 *
31
 * @package OCA\GalleryPlus\Controller
32
 */
33
trait Files {
34
35
	use PathManipulation;
36
37
	/** @var SearchFolderService */
38
	private $searchFolderService;
39
	/** @var ConfigService */
40
	private $configService;
41
	/** @var SearchMediaService */
42
	private $searchMediaService;
43
	/** @var DownloadService */
44
	private $downloadService;
45
	/** @var ILogger */
46
	private $logger;
47
48
	/**
49
	 * @NoAdminRequired
50
	 *
51
	 * Returns a list of all media files and albums available to the authenticated user
52
	 *
53
	 *    * Authentication can be via a login/password or a token/(password)
54
	 *    * For private galleries, it returns all media files, with the full path from the root
55
	 *     folder For public galleries, the path starts from the folder the link gives access to
56
	 *     (virtual root)
57
	 *    * An exception is only caught in case something really wrong happens. As we don't test
58
	 *     files before including them in the list, we may return some bad apples
59
	 *
60
	 * @param string $location a path representing the current album in the app
61
	 * @param array $features the list of supported features
62
	 * @param string $etag the last known etag in the client
63
	 * @param array $mediatypes the list of supported media types
64
	 *
65
	 * @return array <string,array<string,string|int>>|Http\JSONResponse
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,array|string|boolean>.

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...
66
	 */
67 15
	private function getFilesAndAlbums($location, $features, $etag, $mediatypes) {
68 15
		$files = [];
69 15
		$albums = [];
70 15
		$updated = true;
71
		/** @var Folder $folderNode */
72
		list($folderPathFromRoot, $folderNode) =
73 15
			$this->searchFolderService->getCurrentFolder(rawurldecode($location), $features);
74 12
		$albumConfig = $this->configService->getConfig($folderNode, $features);
75 11
		if ($folderNode->getEtag() !== $etag) {
76 8
			list($files, $albums) = $this->searchMediaService->getMediaFiles(
77
				$folderNode, $mediatypes, $features
78
			);
79
		} else {
80 3
			$updated = false;
81
		}
82 11
		$files = $this->fixPaths($files, $folderPathFromRoot);
83
84 11
		return $this->formatResults($files, $albums, $albumConfig, $folderPathFromRoot, $updated);
85
	}
86
87
	/**
88
	 * Generates shortened paths to the media files
89
	 *
90
	 * We only want to keep one folder between the current folder and the found media file
91
	 * /root/folder/sub1/sub2/file.ext
92
	 * becomes
93
	 * /root/folder/file.ext
94
	 *
95
	 * @param array $files
96
	 * @param string $folderPathFromRoot
97
	 *
98
	 * @return array
99
	 */
100 11
	private function fixPaths($files, $folderPathFromRoot) {
101 11
		if (!empty($files)) {
102 7
			foreach ($files as &$file) {
103 7
				$file['path'] = $this->getReducedPath($file['path'], $folderPathFromRoot);
104
			}
105
		}
106
107 11
		return $files;
108
	}
109
110
	/**
111
	 * Simply builds and returns an array containing the list of files, the album information and
112
	 * whether the location has changed or not
113
	 *
114
	 * @param array $files
115
	 * @param array $albums
116
	 * @param array $albumConfig
117
	 * @param string $folderPathFromRoot
118
	 * @param bool $updated
119
	 *
120
	 * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,array|string|boolean>.

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...
121
	 * @internal param $array <string,string|int> $files
122
	 */
123 11
	private function formatResults($files, $albums, $albumConfig, $folderPathFromRoot, $updated) {
124
		return [
125 11
			'files'       => $files,
126 11
			'albums'      => $albums,
127 11
			'albumconfig' => $albumConfig,
128 11
			'albumpath'   => $folderPathFromRoot,
129 11
			'updated'     => $updated
130
		];
131
	}
132
133
	/**
134
	 * Generates the download data
135
	 *
136
	 * @param int $fileId the ID of the file of which we need a large preview of
137
	 * @param string|null $filename
138
	 *
139
	 * @return array|false
140
	 */
141 13
	private function getDownload($fileId, $filename) {
142
		/** @type File $file */
143 13
		$file = $this->downloadService->getFile($fileId);
144 9
		$this->configService->validateMimeType($file->getMimeType());
145 9
		$download = $this->downloadService->downloadFile($file);
146 9
		if (is_null($filename)) {
147 8
			$filename = $file->getName();
148
		}
149 9
		$download['name'] = $filename;
150
151 9
		return $download;
152
	}
153
154
}
155