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.

controller/previewcontroller.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
 * 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 2016
11
 */
12
13
namespace OCA\Gallery\Controller;
14
15
use OCP\IRequest;
16
use OCP\IURLGenerator;
17
use OCP\ILogger;
18
use OCP\Files\File;
19
20
use OCP\AppFramework\Controller;
21
use OCP\AppFramework\Http;
22
use OCP\AppFramework\Http\JSONResponse;
23
24
use OCA\Gallery\Http\ImageResponse;
25
use OCA\Gallery\Service\ConfigService;
26
use OCA\Gallery\Service\ThumbnailService;
27
use OCA\Gallery\Service\PreviewService;
28
use OCA\Gallery\Service\DownloadService;
29
use OCA\Gallery\Utility\EventSource;
30
31
/**
32
 * Class PreviewController
33
 *
34
 * @package OCA\Gallery\Controller
35
 */
36
class PreviewController extends Controller {
37
	use Preview;
38
39
	/** @var EventSource */
40
	private $eventSource;
41
42
	/**
43
	 * Constructor
44
	 *
45
	 * @param string $appName
46
	 * @param IRequest $request
47
	 * @param IURLGenerator $urlGenerator
48
	 * @param ConfigService $configService
49
	 * @param ThumbnailService $thumbnailService
50
	 * @param PreviewService $previewService
51
	 * @param DownloadService $downloadService
52
	 * @param EventSource $eventSource
53
	 * @param ILogger $logger
54
	 */
55 View Code Duplication
	public function __construct(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
		$appName,
57
		IRequest $request,
58
		IURLGenerator $urlGenerator,
59
		ConfigService $configService,
60
		ThumbnailService $thumbnailService,
61
		PreviewService $previewService,
62
		DownloadService $downloadService,
63
		EventSource $eventSource,
64
		ILogger $logger
65
	) {
66
		parent::__construct($appName, $request);
67
68
		$this->urlGenerator = $urlGenerator;
69
		$this->configService = $configService;
70
		$this->thumbnailService = $thumbnailService;
71
		$this->previewService = $previewService;
72
		$this->downloadService = $downloadService;
73
		$this->eventSource = $eventSource;
74
		$this->logger = $logger;
75
	}
76
77
	/**
78
	 * @NoAdminRequired
79
	 *
80
	 * Generates thumbnails
81
	 *
82
	 * Uses EventSource to send thumbnails back as soon as they're created
83
	 *
84
	 * FIXME: @LukasReschke says: The exit is required here because
85
	 * otherwise the AppFramework is trying to add headers as well after
86
	 * dispatching the request which results in a "Cannot modify header
87
	 * information" notice.
88
	 *
89
	 * WARNING: Returning a JSON response does not get rid of the problem
90
	 *
91
	 * @param string $ids the ID of the files of which we need thumbnail previews of
92
	 * @param bool $square
93
	 * @param double $scale
94
	 *
95
	 * @return array<string,array|string|null>
0 ignored issues
show
Should the return type not be array<string,array|string|null>|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
96
	 */
97
	public function getThumbnails($ids, $square, $scale) {
98
		$idsArray = \explode(';', $ids);
99
100
		foreach ($idsArray as $id) {
101
			// Casting to integer here instead of using array_map to extract IDs from the URL
102
			list($thumbnail, $status) = $this->getThumbnail((int)$id, $square, $scale);
103
			$thumbnail['fileid'] = $id;
104
			$thumbnail['status'] = $status;
105
106
			$this->eventSource->send('preview', $thumbnail);
107
		}
108
		$this->eventSource->close();
109
110
		$this->exitController();
111
		// @codeCoverageIgnoreStart
112
	} // @codeCoverageIgnoreEnd
113
114
	/**
115
	 * @NoAdminRequired
116
	 *
117
	 * Sends either a large preview of the requested file or the original file itself
118
	 *
119
	 * @param int $fileId the ID of the file of which we need a large preview of
120
	 * @param int $width
121
	 * @param int $height
122
	 *
123
	 * @return ImageResponse|Http\JSONResponse
124
	 */
125
	public function getPreview($fileId, $width, $height) {
126
		/** @type File $file */
127
		list($file, $preview, $status) = $this->getData($fileId, $width, $height);
128
129
		if (!$preview) {
130
			return new JSONResponse(
131
				[
132
					'message' => "I'm truly sorry, but we were unable to generate a preview for this file",
133
					'success' => false
134
				], $status
135
			);
136
		}
137
		$preview['name'] = $file->getName();
138
139
		return new ImageResponse($preview, $status);
140
	}
141
}
142