Issues (221)

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/Db/RelationalEntity.php (1 issue)

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 Copyright (c) 2017 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *  
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *  
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *  
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *  
22
 */
23
24
namespace OCA\Deck\Db;
25
26
use OCP\AppFramework\Db\Entity;
27
28
class RelationalEntity extends Entity implements \JsonSerializable {
29
30
	private $_relations = array();
31
	private $_resolvedProperties = [];
32
33
	/**
34
	 * Mark a property as relation so it will not get updated using Mapper::update
35
	 * @param string $property string Name of the property
36
	 */
37
	public function addRelation($property) {
38
		if (!in_array($property, $this->_relations, true)) {
39
			$this->_relations[] = $property;
40
		}
41
	}
42
43
	/**
44
	 * Mark a property as resolvable via resolveRelation()
45
	 * @param string $property string Name of the property
46
	 */
47
	public function addResolvable($property) {
48
		$this->_resolvedProperties[$property] = null;
49
	}
50
51
	/**
52
	 * Mark am attribute as updated
53
	 * overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
54
	 * @param string $attribute the name of the attribute
55
	 * @since 7.0.0
56
	 */
57
	protected function markFieldUpdated($attribute) {
58
		if (!in_array($attribute, $this->_relations, true)) {
59
			parent::markFieldUpdated($attribute);
60
		}
61
	}
62
63
	/**
64
	 * @return array serialized data
65
	 * @throws \ReflectionException
66
	 */
67
	public function jsonSerialize() {
68
		$properties = get_object_vars($this);
69
		$reflection = new \ReflectionClass($this);
70
		$json = [];
71
		foreach ($properties as $property => $value) {
72
			if (strpos($property, '_') !== 0 && $reflection->hasProperty($property)) {
73
				$propertyReflection = $reflection->getProperty($property);
74
				if (!$propertyReflection->isPrivate() && !in_array($property, $this->_resolvedProperties, true)) {
75
					$json[$property] = $this->getter($property);
76
				}
77
			}
78
		}
79
		foreach ($this->_resolvedProperties as $property => $value) {
80
			if ($value !== null) {
81
				$json[$property] = $value;
82
			}
83
		}
84
		return $json;
85
	}
86
87
	/*
88
	 * Resolve relational data from external methods
89
	 *
90
	 * example usage:
91
	 *
92
	 * in Board::__construct()
93
	 * 		$this->addResolvable('owner')
94
	 *
95
	 * in BoardMapper
96
	 * 		$board->resolveRelation('owner', function($owner) use (&$userManager) {
97
	 * 			return new \OCA\Deck\Db\User($userManager->get($owner));
98
	 * 		});
99
	 *
100
	 * resolved values can be obtained by calling resolveProperty
101
	 * e.g. $board->resolveOwner()
102
	 *
103
	 * @param string $property name of the property
104
	 * @param callable $resolver anonymous function to resolve relational
105
	 * data defined by $property as unique identifier
106
	 * @throws \Exception
107
	 */
108
	public function resolveRelation($property, $resolver) {
109
		$result = null;
110
		if ($property !== null && $this->$property !== null) {
111
			$result = $resolver($this->$property);
112
		}
113
114
		if ($result instanceof RelationalObject || $result === null) {
115
			$this->_resolvedProperties[$property] = $result;
116
		} else {
117
			throw new \Exception('resolver must return an instance of RelationalObject');
118
		}
119
	}
120
121
	public function __call($methodName, $args) {
122
		$attr = lcfirst(substr($methodName, 7));
123
		if (array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'resolve') === 0) {
124
			if ($this->_resolvedProperties[$attr] !== null) {
125
				return $this->_resolvedProperties[$attr];
126
			}
127
			return $this->getter($attr);
128
		}
129
130
		$attr = lcfirst(substr($methodName, 3));
131
		if (array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'set') === 0) {
132
			if (!is_scalar($args[0])) {
133
				$args[0] = $args[0]['primaryKey'];
134
			}
135
			parent::setter($attr, $args);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setter() instead of __call()). Are you sure this is correct? If so, you might want to change this to $this->setter().

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...
136
			return null;
137
		}
138
		return parent::__call($methodName, $args);
139
	}
140
141
}