Issues (37)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/MetaBox/Condition.php (3 issues)

Labels
1
<?php
2
3
namespace GeminiLabs\Pollux\MetaBox;
4
5
use GeminiLabs\Pollux\Helper;
6
use WP_Post;
7
8
/**
9
 * @property Application $app
10
 */
11
trait Condition
12
{
13
	/**
14
	 * @return array
15
	 */
16
	public static function absolutes()
17
	{
18
		$defaults = [
19
			'class_exists', 'defined', 'function_exists', 'hook', 'is_front_page', 'is_home',
20
			'is_plugin_active', 'is_plugin_inactive',
21
		];
22
		return defined( 'static::ABSOLUTE_CONDITIONS' )
23
			? Helper::toArray( static::ABSOLUTE_CONDITIONS )
0 ignored issues
show
The constant GeminiLabs\Pollux\MetaBo...on::ABSOLUTE_CONDITIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
24
			: $defaults;
25
	}
26
27
	/**
28
	 * @return array
29
	 */
30
	public static function conditions()
31
	{
32
		$defaults = [
33
			'class_exists', 'defined', 'function_exists', 'hook', 'is_front_page', 'is_home',
34
			'is_page_template', 'is_plugin_active', 'is_plugin_inactive',
35
		];
36
		return defined( 'static::CONDITIONS' )
37
			? Helper::toArray( static::CONDITIONS )
0 ignored issues
show
The constant GeminiLabs\Pollux\MetaBox\Condition::CONDITIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
			: $defaults;
39
	}
40
41
	/**
42
	 * @param string $name
43
	 * @param mixed ...$args
44
	 * @return mixed
45
	 */
46
	abstract public function filter( $name, ...$args );
47
48
	/**
49
	 * @return bool
50
	 */
51
	public function validate( array $conditions )
52
	{
53
		array_walk( $conditions, function( &$value, $key ) {
54
			$value = $this->isConditionValid( $key, $value );
55
		});
56
		return !in_array( false, $conditions );
57
	}
58
59
	/**
60
	 * @return int
61
	 */
62
	abstract protected function getPostId();
63
64
	/**
65
	 * @param string $method
66
	 * @return bool
67
	 */
68
	protected function isAbsoluteConditionValid( $method, array $values )
69
	{
70
		foreach( $values as $value ) {
71
			if( $this->$method( $value ))continue;
72
			return false;
73
		}
74
		return true;
75
	}
76
77
	/**
78
	 * @param string $key
79
	 * @param string|array $values
80
	 * @return bool
81
	 */
82
	protected function isConditionValid( $key, $values )
83
	{
84
		$method = Helper::buildMethodName( $key, 'validate' );
85
		if( !method_exists( $this, $method )) {
86
			return $this->validateUnknown( $key, $values );
87
		}
88
		$values = Helper::toArray( $values );
89
		return in_array( $key, $this->absolutes() )
90
			? $this->isAbsoluteConditionValid( $method, $values )
91
			: $this->isLooseConditionValid( $method, $values );
92
	}
93
94
	/**
95
	 * @param string $method
96
	 * @return bool
97
	 */
98
	protected function isLooseConditionValid( $method, array $values )
99
	{
100
		foreach( $values as $value ) {
101
			if( !$this->$method( $value ))continue;
102
			return true;
103
		}
104
		return false;
105
	}
106
107
	/**
108
	 * @param mixed $conditions
109
	 * @return array
110
	 */
111
	protected function normalizeCondition( $conditions )
112
	{
113
		if( !is_array( $conditions )) {
114
			$conditions = [];
115
		}
116
		if( count( array_filter( array_keys( $conditions ), 'is_string' )) == 0 ) {
117
			foreach( $conditions as $key ) {
118
				$conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1;
119
			}
120
			$conditions = array_filter( $conditions, function( $key ) {
121
				return !is_numeric( $key );
122
			}, ARRAY_FILTER_USE_KEY );
123
		}
124
		return array_intersect_key(
125
			$conditions,
126
			array_flip( $this->filter( 'conditions', static::conditions() ))
127
		);
128
	}
129
130
	/**
131
	 * @param string $value
132
	 * @return bool
133
	 */
134
	protected function validateClassExists( $value )
135
	{
136
		return class_exists( $value );
137
	}
138
139
	/**
140
	 * @param string $value
141
	 * @return bool
142
	 */
143
	protected function validateDefined( $value )
144
	{
145
		return defined( $value );
146
	}
147
148
	/**
149
	 * @param string $value
150
	 * @return bool
151
	 */
152
	protected function validateFunctionExists( $value )
153
	{
154
		return function_exists( $value );
155
	}
156
157
	/**
158
	 * @param string $value
159
	 * @return bool
160
	 */
161
	protected function validateHook( $value )
162
	{
163
		return apply_filters( $value, true );
164
	}
165
166
	/**
167
	 * @param bool $value
168
	 * @return bool
169
	 */
170
	protected function validateIsFrontPage( $value )
171
	{
172
		return $value == ( $this->getPostId() == get_option( 'page_on_front' ));
173
	}
174
175
	/**
176
	 * @param bool $value
177
	 * @return bool
178
	 */
179
	protected function validateIsHome( $value )
180
	{
181
		return $value == ( $this->getPostId() == get_option( 'page_for_posts' ));
182
	}
183
184
	/**
185
	 * @param string $value
186
	 * @return bool
187
	 */
188
	protected function validateIsPageTemplate( $value )
189
	{
190
		return Helper::endsWith( $value, basename( get_page_template_slug( $this->getPostId() )));
0 ignored issues
show
It seems like get_page_template_slug($this->getPostId()) can also be of type false; however, parameter $path of basename() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

190
		return Helper::endsWith( $value, basename( /** @scrutinizer ignore-type */ get_page_template_slug( $this->getPostId() )));
Loading history...
191
	}
192
193
	/**
194
	 * @param string $value
195
	 * @return bool
196
	 */
197
	protected function validateIsPluginActive( $value )
198
	{
199
		return $this->app->gatekeeper->isPluginActive( $value );
200
	}
201
202
	/**
203
	 * @param string $value
204
	 * @return bool
205
	 */
206
	protected function validateIsPluginInactive( $value )
207
	{
208
		return !$this->validateIsPluginActive( $value );
209
	}
210
211
	/**
212
	 * @param string $key
213
	 * @param mixed $value
214
	 * @return bool
215
	 */
216
	protected function validateUnknown( $key, $value )
217
	{
218
		return apply_filters( 'pollux/metabox/condition', true, $key, $value );
219
	}
220
}
221