Issues (588)

Security Analysis    no request data  

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/proxycontroller.php (3 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 - Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2016 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
use GuzzleHttp\Exception\RequestException;
25
use GuzzleHttp\Exception\ClientException;
26
use GuzzleHttp\Exception\ConnectException;
27
28
use OCA\Calendar\Http\StreamResponse;
29
30
use OCP\AppFramework\Http;
31
use OCP\AppFramework\Http\JSONResponse;
32
use OCP\AppFramework\Controller;
33
use OCP\Http\Client\IClientService;
34
use OCP\IL10N;
35
use OCP\ILogger;
36
use OCP\IRequest;
37
38
class ProxyController extends Controller {
39
40
	/**
41
	 * @var IClientService
42
	 */
43
	protected $client;
44
45
	/**
46
	 * @var IL10N
47
	 */
48
	protected $l10n;
49
50
	/**
51
	 * @var ILogger
52
	 */
53
	protected $logger;
54
55
	/**
56
	 * @param string $appName
57
	 * @param IRequest $request an instance of the request
58
	 * @param IClientService $client
59
	 * @param IL10N $l10n
60
	 * @param ILogger $logger
61
	 */
62 10
	public function __construct($appName, IRequest $request,
63
								IClientService $client,
64
								IL10N $l10n, ILogger $logger) {
65 10
		parent::__construct($appName, $request);
66 10
		$this->client = $client;
67 10
		$this->l10n = $l10n;
68 10
		$this->logger = $logger;
69 10
	}
70
71
	/**
72
	 * @NoAdminRequired
73
	 *
74
	 * @param $url
75
	 * @return StreamResponse|JSONResponse
76
	 */
77 10
	public function proxy($url) {
78 10
		$client = $this->client->newClient();
79
		try {
80 10
			$queryUrl = $url;
81 10
			$allow_redirects = false; // try to handle redirects manually at first
82 10
			$redirect_count = 0;
83 10
			$max_redirects = 5;
84 10
			$done = false;
85
86
			// try to find a chain of 301s
87
			do {
88 10
				$clientResponse = $client->get($queryUrl, [
89 10
					'stream' => true,
90 10
					'allow_redirects' => $allow_redirects,
91
				]);
92
93 6
				$statusCode = $clientResponse->getStatusCode();
94 6
				if ($statusCode === 301) { // 400+ goes straight to catch
95 4
					$redirect_count++;
96 4
					$queryUrl = $clientResponse->getHeader('Location');
97 5
				} elseif ($statusCode >= 300) {
98 2
					if ($redirect_count > 0) {
99
						// $redirect_count > 0 => There have been 301s before,
100
						// break and return Location from last 301
101 1
						break;
102
					} else {
103
						// this is the very first request
104
						// it's being redirected, but the redirection is not
105
						// permanently, just let Guzzle take care
106
						$allow_redirects = [
107 1
							'max' => $max_redirects
108
						];
109
					}
110
				} else {
111 4
					$done = true;
112
				}
113 6
			} while(!$done && $redirect_count <= $max_redirects);
114
115 6
			if ($redirect_count > 0 && $redirect_count <= $max_redirects) {
116 3
				$response = new JSONResponse([
117 3
					'proxy_code' => -4,
118 3
					'new_url' => $queryUrl,
119 3
				], Http::STATUS_BAD_REQUEST);
120 3
			} elseif ($done) {
121 2
				$response = new StreamResponse($clientResponse->getBody());
122 2
				$response->setHeaders([
123 2
					'Content-Type' => 'text/calendar',
124
				]);
125
			} else {
126 1
				$response = new JSONResponse([
127 1
					'message' => $this->l10n->t('Too many redirects. Aborting ...'),
128
					'proxy_code' => -3
129 6
				], Http::STATUS_UNPROCESSABLE_ENTITY);
130
			}
131 4
		} catch (ClientException $e) {
0 ignored issues
show
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
132 1
			$error_code = $e->getResponse()->getStatusCode();
133 1
			$message = $e->getMessage();
134
135 1
			$this->logger->debug($message);
136 1
			$response = new JSONResponse([
137 1
				'message' => $this->l10n->t('The remote server did not give us access to the calendar (HTTP {%s} error)', [
138 1
					(string) $error_code
139
				]),
140 1
				'proxy_code' => $error_code
141 1
			], Http::STATUS_UNPROCESSABLE_ENTITY);
142 3
		} catch (ConnectException $e) {
0 ignored issues
show
The class GuzzleHttp\Exception\ConnectException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
143 1
			$this->logger->debug($e->getMessage());
144 1
			$response = new JSONResponse([
145 1
				'message' => $this->l10n->t('Error connecting to remote server'),
146
				'proxy_code' => -1
147 1
			], Http::STATUS_UNPROCESSABLE_ENTITY);
148 2
		} catch (RequestException $e) {
0 ignored issues
show
The class GuzzleHttp\Exception\RequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
149 2
			$this->logger->debug($e->getMessage());
150
151 2
			if (substr($url, 0, 8) === 'https://') {
152 1
				$message = $this->l10n->t('Error requesting resource on remote server. This could possibly be related to a certificate mismatch');
153
			} else {
154 1
				$message = $this->l10n->t('Error requesting resource on remote server');
155
			}
156
157 2
			$response = new JSONResponse([
158 2
				'message' => $message,
159
				'proxy_code' => -2,
160 2
			], Http::STATUS_UNPROCESSABLE_ENTITY);
161
		}
162
163 10
		return $response;
164
	}
165
}
166