Issues (493)

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.

lib/sabre/auth.php (4 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
 * @author Arthur Schiwon <[email protected]>
4
 * @author Bart Visscher <[email protected]>
5
 * @author Christian Seiler <[email protected]>
6
 * @author Jakob Sack <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Markus Goetz <[email protected]>
9
 * @author Michael Gapczynski <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Thomas Müller <[email protected]>
12
 * @author Vincent Petry <[email protected]>
13
 *
14
 * @copyright Copyright (c) 2015, ownCloud, Inc.
15
 * @license AGPL-3.0
16
 *
17
 * This code is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License, version 3,
19
 * as published by the Free Software Foundation.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License, version 3,
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
28
 *
29
 */
30
namespace OCA\Contacts\Sabre;
31
32
use Exception;
33
use OCP\ISession;
34
use OCP\IUserSession;
35
use Sabre\DAV\Auth\Backend\AbstractBasic;
36
use Sabre\DAV\Exception\NotAuthenticated;
37
use Sabre\DAV\Exception\ServiceUnavailable;
38
39
class Auth extends AbstractBasic {
40
	const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
41
42
	/** @var ISession */
43
	private $session;
44
	/** @var IUserSession */
45
	private $userSession;
46
47
	/**
48
	 * @param ISession $session
49
	 * @param IUserSession $userSession
50
	 */
51
	public function __construct(ISession $session,
52
								IUserSession $userSession) {
53
		$this->session = $session;
54
		$this->userSession = $userSession;
55
	}
56
57
	/**
58
	 * Whether the user has initially authenticated via DAV
59
	 *
60
	 * This is required for WebDAV clients that resent the cookies even when the
61
	 * account was changed.
62
	 *
63
	 * @see https://github.com/owncloud/core/issues/13245
64
	 *
65
	 * @param string $username
66
	 * @return bool
67
	 */
68
	protected function isDavAuthenticated($username) {
69
		return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
70
		$this->session->get(self::DAV_AUTHENTICATED) === $username;
71
	}
72
73
	/**
74
	 * Validates a username and password
75
	 *
76
	 * This method should return true or false depending on if login
77
	 * succeeded.
78
	 *
79
	 * @param string $username
80
	 * @param string $password
81
	 * @return bool
82
	 */
83
	protected function validateUserPass($username, $password) {
84
		if ($this->userSession->isLoggedIn() &&
85
			$this->isDavAuthenticated($this->userSession->getUser()->getUID())
86
		) {
87
			\OC_Util::setupFS($this->userSession->getUser()->getUID());
88
			$this->session->close();
89
			return true;
90
		} else {
91
			\OC_Util::setUpFS(); //login hooks may need early access to the filesystem
92
			if($this->userSession->login($username, $password)) {
93
				\OC_Util::setUpFS($this->userSession->getUser()->getUID());
94
				$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
95
				$this->session->close();
96
				return true;
97
			} else {
98
				$this->session->close();
99
				return false;
100
			}
101
		}
102
	}
103
104
	/**
105
	 * Returns information about the currently logged in username.
106
	 *
107
	 * If nobody is currently logged in, this method should return null.
108
	 *
109
	 * @return string|null
110
	 */
111
	public function getCurrentUser() {
112
		$user = $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null;
113
		if($user !== null && $this->isDavAuthenticated($user)) {
114
			return $user;
115
		}
116
117
		if($user !== null && is_null($this->session->get(self::DAV_AUTHENTICATED))) {
118
			return $user;
119
		}
120
121
		return null;
122
	}
123
124
	/**
125
	 * Override function here. We want to cache authentication cookies
126
	 * in the syncing client to avoid HTTP-401 roundtrips.
127
	 * If the sync client supplies the cookies, then OC_User::isLoggedIn()
128
	 * will return true and we can see this WebDAV request as already authenticated,
129
	 * even if there are no HTTP Basic Auth headers.
130
	 * In other case, just fallback to the parent implementation.
131
	 *
132
	 * @param \Sabre\DAV\Server $server
133
	 * @param string $realm
134
	 * @return bool
135
	 * @throws ServiceUnavailable
136
	 * @throws NotAuthenticated
137
	 */
138
	public function authenticate(\Sabre\DAV\Server $server, $realm) {
139
		try {
140
			$result = $this->auth($server, $realm);
141
			return $result;
142
		} catch (NotAuthenticated $e) {
0 ignored issues
show
The class Sabre\DAV\Exception\NotAuthenticated 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
			throw $e;
144
		} catch (Exception $e) {
145
			$class = get_class($e);
146
			$msg = $e->getMessage();
147
			throw new ServiceUnavailable("$class: $msg");
148
		}
149
    }
0 ignored issues
show
Tabs must be used to indent lines; spaces are not allowed
Loading history...
150
151
	/**
152
	 * @param \Sabre\DAV\Server $server
153
	 * @param $realm
154
	 * @return bool
155
	 */
156
	private function auth(\Sabre\DAV\Server $server, $realm) {
0 ignored issues
show
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
157
		if (\OC_User::handleApacheAuth() ||
158
			($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED)))
159
		) {
160
			$user = $this->userSession->getUser()->getUID();
161
			\OC_Util::setupFS($user);
162
			$this->currentUser = $user;
163
			$this->session->close();
164
			return true;
165
		}
166
167
		return parent::authenticate($server, $realm);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (authenticate() instead of auth()). Are you sure this is correct? If so, you might want to change this to $this->authenticate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
168
	}
169
}
170