Issues (78)

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.

lib/service/autoconfig/autoconfig.php (5 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
/**
4
 * @author Bernhard Scheirle <[email protected]>
5
 * @author Christoph Wurst <[email protected]>
6
 *
7
 * Mail
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program 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 License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
namespace OCA\Mail\Service\AutoConfig;
23
24
use Horde_Mail_Transport_Smtphorde;
25
use OCP\Security\ICrypto;
26
use OCA\Mail\Account;
27
use OCA\Mail\Db\MailAccount;
28
use OCA\Mail\Service\Logger;
29
30
class AutoConfig {
31
32
	/** @var Logger */
33
	private $logger;
34
35
	/** @var string */
36
	private $userId;
37
38
	/** @var ICrypto */
39
	private $crypto;
40
41
	/** @var IspDb */
42
	private $ispDb;
43
44
	/** @var MxRecord */
45
	private $mxRecord;
46
47
	/** @var ImapConnectivityTester */
48
	private $imapConnectivityTester;
49
50
	/** @var ImapServerDetector */
51
	private $imapServerDetector;
52
53
	/** @var ImapConnector */
54
	private $imapConnector;
55
56
	/** @var SmtpConnectivityTester */
57
	private $smtpConnectivityTester;
58
59
	/** @var SmtpServerDetector */
60
	private $smtpServerDetector;
61
62
	/**
63
	 * 
64
	 * @param Logger $logger
65
	 * @param string $UserId
66
	 * @param IspDb $ispDb
67
	 * @param MxRecord $mxRecord
68
	 * @param ImapConnectivityTester $imapTester
69
	 * @param ImapServerDetector $imapDetector
70
	 * @param SmtpConnectivityTester $smtpTester
71
	 * @param SmtpServerDetector $smtpDetector
72
	 * @param ImapConnector $imapConnector
73
	 * @param ICrypto $crypto
74
	 */
75
	public function __construct(Logger $logger, $UserId,
76
		IspDb $ispDb, MxRecord $mxRecord,
77
		ImapConnectivityTester $imapTester, ImapServerDetector $imapDetector,
78
		SmtpConnectivityTester $smtpTester, SmtpServerDetector $smtpDetector,
79
		ImapConnector $imapConnector, ICrypto $crypto) {
80
		$this->logger = $logger;
81
		$this->userId = $UserId;
82
		$this->crypto = $crypto;
83
		$this->ispDb = $ispDb;
84
		$this->mxRecord = $mxRecord;
85
		$this->imapConnectivityTester = $imapTester;
86
		$this->imapServerDetector = $imapDetector;
87
		$this->imapConnector = $imapConnector;
88
		$this->smtpConnectivityTester = $smtpTester;
89
		$this->smtpServerDetector = $smtpDetector;
90
	}
91
92
	/**
93
	 * @param string $email
94
	 * @param string $password
95
	 * @param string $name
96
	 * @return null|MailAccount
97
	 */
98
	public function createAutoDetected($email, $password, $name) {
99
100
		// splitting the email address into user and host part
101
		// TODO: use horde libs for email address parsing
102
		list(, $host) = explode("@", $email);
103
104
		$ispdb = $this->ispDb->query($host);
105
		if (!empty($ispdb)) {
106
			$account = null;
107
			if (isset($ispdb['imap'])) {
108
				foreach ($ispdb['imap'] as $imap) {
109
					$host = $imap['hostname'];
110
					$port = $imap['port'];
111
					$encryptionProtocol = null;
112
					if ($imap['socketType'] === 'SSL') {
113
						$encryptionProtocol = 'ssl';
114
					}
115
					if ($imap['socketType'] === 'STARTTLS') {
116
						$encryptionProtocol = 'tls';
117
					}
118 View Code Duplication
					if ($imap['username'] === '%EMAILADDRESS%') {
0 ignored issues
show
This code seems to be duplicated across 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...
119
						$user = $email;
120
					} elseif ($imap['username'] === '%EMAILLOCALPART%') {
121
						list($user, ) = explode("@", $email);
122
					} else {
123
						$this->logger->info("Unknown username variable: " . $imap['username']);
124
						return null;
125
					}
126
					try {
127
						$account = $this->imapConnector->connect($email, $password, $name, $host,
128
							$port, $encryptionProtocol, $user);
129
						break;
130
					} catch (\Horde_Imap_Client_Exception $e) {
0 ignored issues
show
The class Horde_Imap_Client_Exception 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...
131
						$error = $e->getMessage();
132
						$this->logger->info("Test-Account-Failed: $this->userId, $host, $port, $user, $encryptionProtocol -> $error");
133
					}
134
				}
135
			}
136
			if (!is_null($account)) {
137
				foreach ($ispdb['smtp'] as $smtp) {
138
					try {
139 View Code Duplication
						if ($smtp['username'] === '%EMAILADDRESS%') {
0 ignored issues
show
This code seems to be duplicated across 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...
140
							$user = $email;
141
						} elseif ($smtp['username'] === '%EMAILLOCALPART%') {
142
							list($user, ) = explode("@", $email);
143
						} else {
144
							$this->logger->info("Unknown username variable: " . $smtp['username']);
145
							return null;
146
						}
147
148
						$account->setOutboundHost($smtp['hostname']);
149
						$account->setOutboundPort($smtp['port']);
150
						$password = $this->crypto->encrypt($password);
151
						$account->setOutboundPassword($password);
152
						$account->setOutboundUser($user);
153
						$account->setOutboundSslMode(strtolower($smtp['socketType']));
154
155
						$a = new Account($account);
156
						$smtp = $a->createTransport();
157
						if ($smtp instanceof Horde_Mail_Transport_Smtphorde) {
0 ignored issues
show
The class Horde_Mail_Transport_Smtphorde does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
158
							$smtp->getSMTPObject();
159
						}
160
161
						break;
162
					} catch (\PEAR_Exception $ex) {
0 ignored issues
show
The class PEAR_Exception 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...
163
						$error = $ex->getMessage();
164
						$this->logger->info("Test-Account-Failed(smtp): $error");
165
					}
166
				}
167
				return $account;
168
			}
169
		}
170
171
		$account = $this->detectImapAndSmtp($email, $password, $name);
172
		if (!is_null($account)) {
173
			return $account;
174
		}
175
176
		return null;
177
	}
178
179
	/**
180
	 * @param $email
181
	 * @param $password
182
	 * @param $name
183
	 * @return null|MailAccount
184
	 */
185
	private function detectImapAndSmtp($email, $password, $name) {
186
		$account = $this->imapServerDetector->detect($email, $password, $name);
187
		if (is_null($account)) {
188
			return null;
189
		}
190
191
		$this->smtpServerDetector->detect($account, $email, $password);
192
193
		return $account;
194
	}
195
196
}
197