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/pagecontroller.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 Robin Appelman <[email protected]>
9
 * @author Olivier Paroz <[email protected]>
10
 *
11
 * @copyright Robin Appelman 2012-2015
12
 * @copyright Olivier Paroz 2014-2016
13
 */
14
15
namespace OCA\Gallery\Controller;
16
17
use OCP\IURLGenerator;
18
use OCP\IRequest;
19
use OCP\IConfig;
20
21
use OCP\AppFramework\Controller;
22
use OCP\AppFramework\Http;
23
use OCP\AppFramework\Http\TemplateResponse;
24
use OCP\AppFramework\Http\RedirectResponse;
25
26
use OCA\Gallery\Environment\Environment;
27
use OCA\Gallery\Http\ImageResponse;
28
29
/**
30
 * Generates templates for the landing page from within ownCloud, the public
31
 * gallery and error pages
32
 *
33
 * @package OCA\Gallery\Controller
34
 */
35
class PageController extends Controller {
36
37
	/** @var Environment */
38
	private $environment;
39
	/** @var IURLGenerator */
40
	private $urlGenerator;
41
	/** @var IConfig */
42
	private $appConfig;
43
44
	/**
45
	 * Constructor
46
	 *
47
	 * @param string $appName
48
	 * @param IRequest $request
49
	 * @param Environment $environment
50
	 * @param IURLGenerator $urlGenerator
51
	 * @param IConfig $appConfig
52
	 */
53
	public function __construct(
54
		$appName,
55
		IRequest $request,
56
		Environment $environment,
57
		IURLGenerator $urlGenerator,
58
		IConfig $appConfig
59
	) {
60
		parent::__construct($appName, $request);
61
62
		$this->environment = $environment;
63
		$this->urlGenerator = $urlGenerator;
64
		$this->appConfig = $appConfig;
65
	}
66
67
	/**
68
	 * @NoAdminRequired
69
	 * @NoCSRFRequired
70
	 *
71
	 * Shows the albums and pictures at the root folder or a message if
72
	 * there are no pictures.
73
	 *
74
	 * This is the entry page for logged-in users accessing the app from
75
	 * within ownCloud.
76
	 * A TemplateResponse response uses a template from the templates folder
77
	 * and parameters provided here to build the page users will see
78
	 *
79
	 * @return TemplateResponse
80
	 */
81
	public function index() {
82
		$appName = $this->appName;
83
84
		// Parameters sent to the template
85
		$params = $this->getIndexParameters($appName);
86
87
		// Will render the page using the template found in templates/index.php
88
		$response = new TemplateResponse($appName, 'index', $params);
89
		$this->addContentSecurityToResponse($response);
90
91
		return $response;
92
	}
93
94
	/**
95
	 * @PublicPage
96
	 * @NoCSRFRequired
97
	 *
98
	 * Shows the albums and pictures or redirects to the download location the token gives access to
99
	 *
100
	 * @param string $token
101
	 * @param null|string $filename
102
	 *
103
	 * @return TemplateResponse|ImageResponse|RedirectResponse
0 ignored issues
show
Consider making the return type a bit more specific; maybe use TemplateResponse|RedirectResponse.

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...
104
	 */
105
	public function publicIndex($token, $filename) {
106
		$node = $this->environment->getSharedNode();
107
		if ($node->getType() === 'dir') {
108
			return $this->showPublicPage($token);
109
		} else {
110
			$url = $this->urlGenerator->linkToRoute(
111
				$this->appName . '.files_public.download',
112
				[
113
					'token'    => $token,
114
					'fileId'   => $node->getId(),
115
					'filename' => $filename
116
				]
117
			);
118
119
			return new RedirectResponse($url);
120
		}
121
	}
122
123
	/**
124
	 * @PublicPage
125
	 * @NoCSRFRequired
126
	 * @Guest
127
	 *
128
	 * Generates an error page based on the error code
129
	 *
130
	 * @param int $code
131
	 *
132
	 * @return TemplateResponse
133
	 */
134
	public function errorPage($code) {
135
		$appName = $this->appName;
136
		$message = $this->request->getCookie('galleryErrorMessage');
137
		$params = [
138
			'appName' => $appName,
139
			'message' => $message,
140
			'code'    => $code,
141
		];
142
143
		$errorTemplate = new TemplateResponse($appName, 'index', $params, 'guest');
144
		$errorTemplate->setStatus($code);
145
		$errorTemplate->invalidateCookie('galleryErrorMessage');
146
147
		return $errorTemplate;
148
	}
149
150
	/**
151
	 * Adds the domain "data:" to the allowed image domains
152
	 * this function is called by reference
153
	 *
154
	 * @param TemplateResponse $response
155
	 */
156
	private function addContentSecurityToResponse($response) {
157
		$csp = new Http\ContentSecurityPolicy();
158
		$csp->addAllowedFontDomain("data:");
159
		$response->setContentSecurityPolicy($csp);
160
	}
161
162
	/**
163
	 * @PublicPage
164
	 * @NoCSRFRequired
165
	 * @Guest
166
	 *
167
	 * Returns the slideshow template
168
	 *
169
	 * @return TemplateResponse
170
	 */
171
	public function slideshow() {
172
		return new TemplateResponse($this->appName, 'slideshow', [], 'blank');
173
	}
174
175
	/**
176
	 * Returns the parameters to be used in the index function
177
	 *
178
	 * @param $appName
179
	 *
180
	 * @return array<string,string>
181
	 */
182
	private function getIndexParameters($appName) {
183
184
		// Parameters sent to the index function
185
		$params = [
186
			'appName' => $appName,
187
			'uploadUrl' => $this->urlGenerator->linkTo(
188
				'files', 'ajax/upload.php'
189
			),
190
			'publicUploadEnabled' => $this->appConfig->getAppValue(
191
				'core', 'shareapi_allow_public_upload', 'yes'
192
			),
193
			'mailNotificationEnabled' => $this->appConfig->getAppValue(
194
				'core', 'shareapi_allow_mail_notification', 'no'
195
			),
196
			'mailPublicNotificationEnabled' => $this->appConfig->getAppValue(
197
				'core', 'shareapi_allow_public_notification', 'no'
198
			)
199
		];
200
201
		return $params;
202
	}
203
204
	/**
205
	 * Shows the albums and pictures the token gives access to
206
	 *
207
	 * @param $token
208
	 *
209
	 * @return TemplateResponse
210
	 */
211
	private function showPublicPage($token) {
212
		$albumName = $this->environment->getSharedFolderName();
213
		list($server2ServerSharing, $protected) = $this->getServer2ServerProperties();
214
215
		// Parameters sent to the template
216
		$params = [
217
			'appName'              => $this->appName,
218
			'token'                => $token,
219
			'displayName'          => $this->environment->getDisplayName(),
220
			'albumName'            => $albumName,
221
			'server2ServerSharing' => $server2ServerSharing,
222
			'protected'            => $protected,
223
			'filename'             => $albumName
224
		];
225
226
		// Will render the page using the template found in templates/public.php
227
		$response = new TemplateResponse($this->appName, 'public', $params, 'public');
228
		$this->addContentSecurityToResponse($response);
229
230
		return $response;
231
	}
232
233
	/**
234
	 * Determines if we can add external shared to this instance
235
	 *
236
	 * @return array<bool,string>
0 ignored issues
show
Should the return type not be array<boolean|string>?

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...
237
	 */
238
	private function getServer2ServerProperties() {
239
		$server2ServerSharing = $this->appConfig->getAppValue(
240
			'files_sharing', 'outgoing_server2server_share_enabled', 'yes'
241
		);
242
		$server2ServerSharing = ($server2ServerSharing === 'yes') ? true : false;
243
		$password = $this->environment->getSharePassword();
244
		$passwordProtected = ($password) ? 'true' : 'false';
245
246
		return [$server2ServerSharing, $passwordProtected];
247
	}
248
}
249