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/unifiedmailbox.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
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Thomas Müller <[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;
23
24
use OCA\Mail\Attachment;
25
use OCA\Mail\Message;
26
27
class UnifiedMailbox implements IMailBox {
28
29
	/**
30
	 * @param string $userId
31
	 */
32
	public function __construct(AccountService $accountService, $userId) {
33
		$this->accountService = $accountService;
0 ignored issues
show
The property accountService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
		$this->userId = $userId;
0 ignored issues
show
The property userId does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
	}
36
37
	/**
38
	 * @return string
39
	 */
40
	public function getFolderId() {
41
		// TODO: Implement getFolderId() method.
42
	}
43
44
	/**
45
	 * @param int $from
46
	 * @param int $count
47
	 * @param string|\Horde_Imap_Client_Search_Query $filter
48
	 * @return array
49
	 */
50
	public function getMessages($from, $count, $filter) {
51
		$allAccounts = $this->accountService->findByUserId($this->userId);
52
		$allMessages = array_map(function($account) use ($from, $count, $filter) {
53
			/** @var IAccount $account */
54
			if ($account->getId() === UnifiedAccount::ID) {
55
				return [];
56
			}
57
			$inbox = $account->getInbox();
58
			if (is_null($inbox)) {
59
				return [];
60
			}
61
62
			$messages = $inbox->getMessages($from, $count, $filter);
63
			$messages = array_map(function($message) use ($account) {
64
				$message['id'] = base64_encode(json_encode([$account->getId(), $message['id']]));
65
				$message['accountMail'] = $account->getEmail();
66
				return $message;
67
			}, $messages);
68
69
			return $messages;
70
		}, $allAccounts);
71
72
		$allMessages = array_reduce($allMessages, function($a, $b) {
73
			if (is_null($a)) {
74
				return $b;
75
			}
76
			if (is_null($b)) {
77
				return $a;
78
			}
79
			return array_merge($a, $b);
80
		});
81
82
		// sort by time
83
		usort($allMessages, function($a, $b) {
84
			return $a['dateInt'] < $b['dateInt'];
85
		});
86
87
		if ($count >= 0) {
88
			$allMessages = array_slice($allMessages, 0, $count);
89
		}
90
91
		return $allMessages;
92
	}
93
94
	/**
95
	 * @return string
96
	 */
97
	public function getSpecialRole() {
98
		return 'inbox';
99
	}
100
101
	/**
102
	 * @param string $messageId
103
	 * @return Message
104
	 */
105
	public function getMessage($messageId, $loadHtmlMessageBody = false) {
106
		/** @var IMailBox $inbox */
107
		/** @var IAccount $account */
108
		list($inbox, $messageId, $account) = $this->resolve($messageId);
109
		/** @var Message $message */
110
		$message = $inbox->getMessage($messageId, $loadHtmlMessageBody);
111
		$message->setUid(base64_encode(json_encode([$account->getId(), $message->getUid()])));
112
113
		return $message;
114
	}
115
116
	/**
117
	 * @param string $messageId
118
	 * @param string $attachmentId
119
	 * @return Attachment
120
	 */
121
	public function getAttachment($messageId, $attachmentId) {
122
		/** @var IMailBox $inbox */
123
		list($inbox, $messageId) = $this->resolve($messageId);
124
		return $inbox->getAttachment($messageId, $attachmentId);
125
	}
126
127
	/**
128
	 * @param string $messageId
129
	 * @param string $flag
130
	 * @param mixed $value
131
	 */
132
	public function setMessageFlag($messageId, $flag, $value) {
133
		/** @var IMailBox $inbox */
134
		list($inbox, $messageId) = $this->resolve($messageId);
135
		return $inbox->setMessageFlag($messageId, $flag, $value);
136
	}
137
138
	/**
139
	 * @return array
140
	 */
141
	public function getStatus() {
142
		return [];
143
	}
144
145
	/**
146
	 * @param string $messageId
147
	 * @return array
148
	 */
149 View Code Duplication
	private function resolve($messageId) {
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...
150
		$data = json_decode(base64_decode($messageId), true);
151
		$account = $this->accountService->find($this->userId, $data[0]);
152
		$inbox = $account->getInbox();
153
		$messageId = $data[1];
154
		return array($inbox, $messageId, $account);
155
	}
156
}
157