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.

tests/unit/lib/backend/mock.php (30 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
 * Copyright (c) 2013 Thomas Tanghus ([email protected])
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
namespace OCA\Contacts\Backend;
10
11
class Mock extends AbstractBackend {
12
13
	public $name = 'mock';
14
	public $addressBooks;
15
	public $contacts;
16
	public $userid;
17
18
	/**
19
	 * @param string $userid
20
	 */
21
	function __construct($userid = null, $addressBooks = null, $contacts = null) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
22
23
		$this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId();
24
		$this->addressBooks = $addressBooks;
25
		$this->contacts = $contacts;
26
27
		if (is_null($this->addressBooks)) {
28
			$this->addressBooks = array(
29
				array(
30
					'id' => 'foo',
31
					'owner' => $userid,
32
					'displayname' => 'd-name',
33
					'permissions' => \OCP\PERMISSION_ALL,
34
				),
35
			);
36
37
			$this->contacts = array(
38
				'foo' => array(
39
					'123' =>
40
					array(
41
						'id' => '123',
42
						'displayname' => 'Max Mustermann',
43
						'carddata' => file_get_contents(__DIR__ . '/../../data/test1.vcf')
44
					)
45
				),
46
			);
47
		}
48
49
	}
50
51
52
	function getAddressBooksForUser(array $options = array()) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getAddressBooksForUser.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
53
54
		$books = array();
55
		foreach($this->addressBooks as $book) {
56
			if ($book['owner'] === $this->userid) {
57
				$books[] = $book;
58
			}
59
		}
60
		return $books;
61
62
	}
63
64
	function getAddressBook($addressBookId, array $options = array()) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getAddressBook.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
65
66
		foreach($this->addressBooks as &$book) {
67
			if ($book['id'] === $addressBookId) {
68
				return $book;
69
			}
70
		}
71
72
	}
73
74
	function updateAddressBook($addressBookId, array $changes, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for updateAddressBook.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
75
76
		if(count($changes) === 0 || !isset($changes['displayname'])) {
77
			return false;
78
		}
79
80
		foreach($this->addressBooks as &$book) {
81
			if ($book['id'] === $addressBookId) {
82
				foreach($changes as $key => $value) {
83
					$book[$key] = $value;
84
					return true;
85
				}
86
			}
87
		}
88
89
		return false;
90
91
	}
92
93
	function createAddressBook(array $properties, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for createAddressBook.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
94
95
		if(count($properties) === 0 || !isset($properties['displayname'])) {
96
			return false;
97
		}
98
99
		$id = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate('4');
100
		$this->addressBooks[] = array_merge($properties, array(
101
			'id' => $id,
102
			'permissions' => \OCP\PERMISSION_ALL,
103
			'owner' => $this->userid,
104
		));
105
106
		return $id;
107
	}
108
109
	function deleteAddressBook($addressBookId, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for deleteAddressBook.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
110
111
		foreach($this->addressBooks as $key => $value) {
112
			if ($value['id'] === $addressBookId) {
113
				unset($this->addressBooks[$key]);
114
			}
115
		}
116
		if(isset($this->contacts[$addressBookId])) {
117
			unset($this->contacts[$addressBookId]);
118
			return true;
119
		}
120
		return false;
121
122
	}
123
124
	function getContacts($addressBookId, array $options = array()) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getContacts.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
125
126
		$contacts = array();
127
		$omitdata = isset($options['omitdata']) ? $options['omitdata'] : false;
128
		$book = $this->getAddressBook($addressBookId);
129
		if(!$book) {
130
			return $contacts;
131
		}
132
		foreach($this->contacts[$addressBookId] as $contact) {
133
			$contact['permissions'] = $book['permissions'];
134
			$contact['owner'] = $book['owner'];
135
			if($omitdata) {
136
				unset($contact['carddata']);
137
			}
138
			$contacts[] = $contact;
139
		}
140
141
		return $contacts;
142
143
	}
144
145
	function getContact($addressBookId, $id, array $options = array()) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getContact.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
146
147
		$book = $this->getAddressBook($addressBookId);
148
		if(!$book) {
149
			return null;
150
		}
151
		if (!isset($this->contacts[$addressBookId][$id])) {
152
			return null;
153
		}
154
155
		$contact = $this->contacts[$addressBookId][$id];
156
		$contact['permissions'] = $book['permissions'];
157
		$contact['owner'] = $book['owner'];
158
159
		return $contact;
160
161
	}
162
163
	function createContact($addressBookId, $contact, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for createContact.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
164
165
		$id = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate('4');
166
		$this->contacts[$addressBookId][$id] = array(
167
						'id' => $id,
168
						'displayname' => $contact->FN,
169
						'carddata' => $contact->serialize()
170
					);
171
172
		return $id;
173
	}
174
175
	function updateContact($addressBookId, $id, $contact, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for updateContact.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
176
		//echo __METHOD__ . $addressBookId .', ' . $id . ', ' . print_r($contact, true);
177
		$this->contacts[$addressBookId][$id] = array(
178
						'displayname' => $contact->FN,
179
						'carddata' => $contact->serialize()
180
					);
181
182
		return true;
183
184
	}
185
186
	function deleteContact($addressBookId, $id, array $options = array()) {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for deleteContact.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
187
188
		if(isset($this->contacts[$addressBookId][$id])) {
189
			unset($this->contacts[$addressBookId][$id]);
190
			return true;
191
		}
192
		return false;
193
194
	}
195
196
	function numContacts($addressBookId) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for numContacts.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
197
		return count($this->contacts[$addressBookId]);
198
	}
199
}
200