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/share/addressbook.php (2 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 Bart Visscher
4
 * @copyright 2012 Bart Visscher <[email protected]>
5
 * @copyright 2013-2014 Thomas Tanghus ([email protected])
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later.
9
 * See the COPYING-README file.
10
 */
11
12
namespace OCA\Contacts\Share;
13
use OCA\Contacts\App;
14
15
class Addressbook implements \OCP\Share_Backend_Collection {
16
	const FORMAT_ADDRESSBOOKS = 1;
17
	const FORMAT_COLLECTION = 2;
18
19
	/**
20
	 * @var \OCA\Contacts\App;
21
	 */
22
	public $app;
23
24
	public function __construct() {
25
		$this->app = new App(\OC::$server->getUserSession()->getUser()->getUId());
26
	}
27
28
	/**
29
	* @brief Get the source of the item to be stored in the database
30
	* @param string Item
31
	* @param string Owner of the item
32
	* @return boolean Source
33
	*
34
	* Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
35
	* Return false if the item does not exist for the user
36
	*
37
	* The formatItems() function will translate the source returned back into the item
38
	*/
39
	public function isValidSource($itemSource, $uidOwner) {
40
		$app = new App($uidOwner);
41
42
		try {
43
			$app->getAddressBook('local', $itemSource);
44
		} catch(\Exception $e) {
45
			return false;
46
		}
47
		return true;
48
	}
49
50
	/**
51
	* @brief Get a unique name of the item for the specified user
52
	* @param string Item
53
	* @param string|false User the item is being shared with
54
	* @param array|null List of similar item names already existing as shared items
55
	* @return string Target name
56
	*
57
	* This function needs to verify that the user does not already have an item with this name.
58
	* If it does generate a new name e.g. name_#
59
	*/
60
	public function generateTarget($itemSource, $shareWith, $exclude = null) {
61
		// Get app for the sharee
62
		$app = new App($shareWith);
63
		$backend = $app->getBackend('local');
64
65
		// Get address book for the owner
66
		$addressBook = $this->app->getBackend('local')->getAddressBook($itemSource);
67
68
		$userAddressBooks = array();
69
70
		foreach($backend->getAddressBooksForUser() as $userAddressBook) {
71
			$userAddressBooks[] = $userAddressBook['displayname'];
72
		}
73
		$name = $addressBook['displayname'] . '(' . $addressBook['owner'] . ')';
74
		$suffix = '';
75
		while (in_array($name.$suffix, $userAddressBooks)) {
76
			$suffix++;
77
		}
78
79
		$suffix = $suffix ? ' ' . $suffix : '';
80
		return $name.$suffix;
81
	}
82
83
	/**
84
	* @brief Converts the shared item sources back into the item in the specified format
85
	* @param array Shared items
86
	* @param int Format
87
	* @return ?
0 ignored issues
show
The doc-type ? could not be parsed: Unknown type name "?" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
88
	*
89
	* The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
90
	* The key/value pairs included in the share info depend on the function originally called:
91
	* If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
92
	* If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
93
	* This function allows the backend to control the output of shared items with custom formats.
94
	* It is only called through calls to the public getItem(s)Shared(With) functions.
95
	*/
96
	public function formatItems($items, $format, $parameters = null, $include = false) {
97
		//\OCP\Util::writeLog('contacts', __METHOD__
98
		//	. ' ' . $include . ' ' . print_r($items, true), \OCP\Util::DEBUG);
99
		$addressBooks = array();
100
		$backend = $this->app->getBackend('local');
101
102
		if ($format === self::FORMAT_ADDRESSBOOKS) {
103
			foreach ($items as $item) {
104
				//\OCP\Util::writeLog('contacts', __METHOD__.' item_source: ' . $item['item_source'] . ' include: '
105
				//	. (int)$include, \OCP\Util::DEBUG);
106
				$addressBook = $backend->getAddressBook($item['item_source'], array('shared_by' => $item['uid_owner']));
107
				if ($addressBook) {
108
					$addressBook['displayname'] = $addressBook['displayname'] . ' (' . $addressBook['owner'] . ')';
109
					$addressBook['permissions'] = $item['permissions'];
110
					$addressBooks[] = $addressBook;
111
				}
112
			}
113
		} elseif ($format === self::FORMAT_COLLECTION) {
114
			foreach ($items as $item) {
0 ignored issues
show
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
115
			}
116
		}
117
		return $addressBooks;
118
	}
119
120
	public function getChildren($itemSource) {
121
		\OCP\Util::writeLog('contacts', __METHOD__.' item_source: ' . $itemSource, \OCP\Util::DEBUG);
122
		$contacts = $this->app->getBackend('local')->getContacts($itemSource);
123
		$children = array();
124
		foreach($contacts as $contact) {
125
			$children[] = array('source' => $contact['id'], 'target' => $contact['displayname']);
126
		}
127
		return $children;
128
	}
129
130
	public function isShareTypeAllowed($shareType) {
131
		return true;
132
	}
133
134
}
135