Issues (8)

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.

src/Knot/Dict/PathOperationsTrait.php (1 issue)

Labels
Severity

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 namespace Knot\Dict;
2
3
use Knot\Exceptions\WrongArrayPathException;
4
5
trait PathOperationsTrait {
6
7
	/**
8
	 * For parsing array path.
9
	 */
10
	public static $ARRAY_PATH_DELIMITER = ".";
11
12
	/**
13
	 * @var string
14
	 */
15
	protected $path = '';
16
17
18
	abstract public function childParent();
19
20
21
	/**
22
	 * @param null $add
23
	 *
24
	 * @return null|string
25
	 */
26
	public function path($add = null)
27
	{
28
		return $add ? $this->path != null ? $this->path . self::$ARRAY_PATH_DELIMITER . $add : $add : $this->path;
29
	}
30
31
32
	/**
33
	 * @param $path
34
	 *
35
	 * @return array
36
	 */
37
	public static function pathParser($path)
38
	{
39
		return explode(self::$ARRAY_PATH_DELIMITER, $path);
40
	}
41
42
43
	/**
44
	 * @param array $path
45
	 *
46
	 * @return string
47
	 */
48
	public static function pathCombiner(array $path)
49
	{
50
		return implode(self::$ARRAY_PATH_DELIMITER, $path);
51
	}
52
53
54
	/**
55
	 * @param $path
56
	 *
57
	 * @return bool
58
	 */
59
	public function isPath($path)
60
	{
61
		try
62
		{
63
			$this->get($path);
64
65
			return true;
66
		}
67
		catch (WrongArrayPathException $e)
68
		{
69
			return false;
70
		}
71
	}
72
73
74
	/**
75
	 * @param $path
76
	 *
77
	 * @return array|ChildDict|Mixed
78
	 * @throws WrongArrayPathException
79
	 */
80
	public function get($path)
81
	{
82
		$arguments = func_get_args();
83
84
		if ( isset( $arguments[1] ) )
85
		{
86
			$default_return = $arguments[1];
87
		}
88
89
		$target_data =& $this->data;
0 ignored issues
show
The property data 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...
90
91
		foreach (static::pathParser($path) as $way)
92
		{
93
94
			if ( ! isset( $target_data[$way] ) )
95
			{
96
97
				if ( isset( $default_return ) )
98
				{
99
					$r = $this->set($path, $default_return);
100
101
					return $r;
102
				}
103
104
				throw new WrongArrayPathException($path);
105
			}
106
107
			$target_data = &$target_data[$way];
108
		}
109
110
		if ( is_array($target_data) )
111
		{
112
			return new ChildDict($target_data, $this->childParent(), $path);
113
		}
114
115
		return $target_data;
116
	}
117
118
119
	/**
120
	 * For Get path without parsing default return to data.
121
	 *
122
	 * @param $path
123
	 *
124
	 * @return Mixed
125
	 * @throws WrongArrayPathException
126
	 */
127
	public function getOnly($path)
128
	{
129
		$arguments = func_get_args();
130
131
		if ( isset( $arguments[1] ) )
132
		{
133
			$value = $arguments[1];
134
		}
135
136
		try
137
		{
138
			return $this->get($path);
139
		}
140
		catch (WrongArrayPathException $e)
141
		{
142
			if ( isset( $value ) )
143
			{
144
				return $this->value($value, [ $path ]);
145
			}
146
147
			throw $e;
148
		}
149
	}
150
151
152
	/**
153
	 * @param $rawPath
154
	 * @param $value
155
	 *
156
	 * @return Mixed|\Knot\Dict\ChildDict
157
	 */
158
	public function set($rawPath, $value)
159
	{
160
		$target_data =& $this->data;
161
162
		foreach (static::pathParser($rawPath) as $path)
163
		{
164
			// If there is no way to go or this is not an array!
165
			if ( ! isset( $target_data[$path] ) || ! is_array($target_data[$path]) )
166
			{
167
				$target_data[$path] = [ ];
168
			}
169
170
			$target_data =& $target_data[$path];
171
		}
172
173
		$value = $this->value($value, [ $rawPath ]);
174
175
		$target_data = $value;
176
177
		if ( is_array($target_data) )
178
		{
179
			return new ChildDict($target_data, $this->childParent(), $this->path());
180
		}
181
182
		return $value;
183
	}
184
185
186
	/**
187
	 * @param $rawPath
188
	 *
189
	 * @return $this
190
	 */
191
	public function del($rawPath)
192
	{
193
		$target_data =& $this->data;
194
195
		$paths = static::pathParser($rawPath);
196
197
		$target_key = array_pop($paths);
198
199
		foreach ($paths as $path)
200
		{
201
			// If there is no way to go or this is not an array!
202
			if ( ! isset( $target_data[$path] ) || ! is_array($target_data[$path]) )
203
			{
204
				return $this;
205
			}
206
207
			$target_data =& $target_data[$path];
208
		}
209
210
		if ( isset( $target_data[$target_key] ) )
211
		{
212
			unset( $target_data[$target_key] );
213
		}
214
215
		return $this;
216
	}
217
218
219
	protected function value($value, array $arguments = [ ])
220
	{
221
		return $value instanceof \Closure ? call_user_func_array($value, $arguments) : $value;
222
	}
223
}