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.

preview/preview.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\Preview;
14
15
use OCP\Files\Folder;
16
use OCP\IConfig;
17
use OCP\Image;
18
use OCP\Files\File;
19
use OCP\IPreview;
20
use OCP\ILogger;
21
22
/**
23
 * Generates previews
24
 *
25
 * @todo On OC9, replace \OC\Preview with IPreview if methods we need have been added
26
 *
27
 * @package OCA\Gallery\Preview
28
 */
29
class Preview {
30
31
	/**
32
	 * @var string
33
	 */
34
	private $dataDir;
35
	/**
36
	 * @var mixed
37
	 */
38
	private $previewManager;
39
	/**
40
	 * @var ILogger
41
	 */
42
	private $logger;
43
	/**
44
	 * @var string
45
	 */
46
	private $userId;
47
	/**
48
	 * @var \OC\Preview
49
	 */
50
	private $preview;
51
	/**
52
	 * @var File
53
	 */
54
	private $file;
55
	/**
56
	 * @var int[]
57
	 */
58
	private $dims;
59
60
	/**
61
	 * Constructor
62
	 *
63
	 * @param IConfig $config
64
	 * @param IPreview $previewManager
65
	 * @param ILogger $logger
66
	 */
67
	public function __construct(
68
		IConfig $config,
69
		IPreview $previewManager,
70
		ILogger $logger
71
	) {
72
		$this->dataDir = $config->getSystemValue('datadirectory');
73
		$this->previewManager = $previewManager;
74
		$this->logger = $logger;
75
	}
76
77
	/**
78
	 * Returns true if the passed mime type is supported
79
	 *
80
	 * @param string $mimeType
81
	 *
82
	 * @return boolean
83
	 */
84
	public function isMimeSupported($mimeType = '*') {
85
		return $this->previewManager->isMimeSupported($mimeType);
86
	}
87
88
	/**
89
	 * Initialises the view which will be used to access files and generate previews
90
	 *
91
	 * @fixme Private API, but can't use the PreviewManager yet as it's incomplete
92
	 *
93
	 * @param string $userId
94
	 * @param File $file
95
	 * @param string $imagePathFromFolder
96
	 */
97
	public function setupView($userId, $file, $imagePathFromFolder) {
98
		$this->userId = $userId;
99
		$this->file = $file;
100
		$imagePathFromFolder = \ltrim($imagePathFromFolder, '/');
101
		if (\version_compare(\implode('.', \OCP\Util::getVersion()), '10.0.9', '>=')) {
102
			/** @var Folder $userFolder */
103
			$userFolder = \OC::$server->getUserFolder($userId);
104
			$node = $userFolder->get($imagePathFromFolder);
105
			$this->preview = new \OC\Preview($userId, 'files', $node);
106
		} else {
107
			$this->preview = new \OC\Preview($userId, 'files', $imagePathFromFolder);
108
		}
109
	}
110
111
	/**
112
	 * Returns a preview based on OC's preview class and our custom methods
113
	 *
114
	 * We check that the preview returned by the Preview class can be used by
115
	 * the browser. If not, we send "false" to the controller
116
	 *
117
	 * @fixme setKeepAspect is missing from public interface.
118
	 *     https://github.com/owncloud/core/issues/12772
119
	 *
120
	 * @param int $maxWidth
121
	 * @param int $maxHeight
122
	 * @param bool $keepAspect
123
	 *
124
	 * @return array<string,string|\OC_Image>|false
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array|false.

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...
125
	 */
126
	public function preparePreview($maxWidth, $maxHeight, $keepAspect) {
127
		$this->dims = [$maxWidth, $maxHeight];
128
129
		$previewData = $this->getPreviewFromCore($keepAspect);
130
131
		if ($previewData && $previewData->valid()) {
132
			$preview = [
133
				'preview'  => $previewData,
134
				'mimetype' => $previewData->mimeType()
135
			];
136
		} else {
137
			$preview = false;
138
		}
139
140
		return $preview;
141
	}
142
143
	/**
144
	 * Asks core for a preview based on our criteria
145
	 *
146
	 * @todo Need to read scaling setting from settings
147
	 *
148
	 * @param bool $keepAspect
149
	 *
150
	 * @return \OC_Image
151
	 */
152
	private function getPreviewFromCore($keepAspect) {
153
		list($maxX, $maxY) = $this->dims;
154
155
		$this->preview->setMaxX($maxX);
156
		$this->preview->setMaxY($maxY);
157
		$this->preview->setScalingUp(false);
158
		$this->preview->setKeepAspect($keepAspect);
159
		
160
		//$this->logger->debug("[PreviewService] preview {preview}", ['preview' => $this->preview]);
161
162
		$previewData = $this->preview->getPreview();
163
164
		return $previewData;
165
	}
166
}
167