Issues (27)

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.

app/core/classes/Menu.php (3 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
 * Class for handling menu functionality.
4
 *
5
 * @package Classy
6
 */
7
8
namespace Classy;
9
10
/**
11
 * Class Menu.
12
 */
13
class Menu {
14
15
	/**
16
	 * Menu ID.
17
	 *
18
	 * @var int
19
	 */
20
	public $ID;
21
22
	/**
23
	 * Menu title.
24
	 *
25
	 * @var string
26
	 */
27
	public $title;
28
29
	/**
30
	 * Items.
31
	 *
32
	 * @var array
33
	 */
34
	protected $items;
35
36
	/**
37
	 * Main constructor. Tries to find menu id based on provided arg (or not) and inits menu.
38
	 *
39
	 * @param string $arg It can be menu id, slug or full name.
40
	 */
41
	public function __construct( $arg = null ) {
42
		$locations = get_nav_menu_locations();
43
44
		if ( is_numeric( $arg ) && 0 !== absint( $arg ) ) {
45
			$menu_id = $this->check_menu_id( $arg );
46
		} elseif ( is_string( $arg ) ) {
47
			$menu_id = $this->get_menu_id_by_name( $arg );
48
		} elseif ( is_array( $locations ) && count( $locations ) ) {
49
			$menu_id = $this->get_locations_menu_id( $locations, $arg );
50
		}
51
52
		if ( ! isset( $menu_id ) ) {
53
			$menu_id = $this->get_first_menu_id();
54
		}
55
56
		if ( $menu_id ) {
57
			$this->ID = $menu_id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $menu_id can also be of type boolean. However, the property $ID is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
58
			$this->title = $this->get_menu_name_by_id();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->get_menu_name_by_id() of type integer or boolean is incompatible with the declared type string of property $title.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
			$this->init();
60
		}
61
	}
62
63
	/**
64
	 * Init menu.
65
	 */
66
	protected function init() {
67
		$_return = array();
68
		$items = wp_get_nav_menu_items( $this->ID );
69
70
		foreach ( $items as $item ) {
71
			$_return[ $item->ID ] = new Menu_Item( $item );
72
		}
73
74
		// Apply nesting.
75
		foreach ( $_return as $item_id => $item ) {
76
			if (
77
				isset( $item->menu_item_parent ) &&
78
				$item->menu_item_parent &&
79
				isset( $_return[ $item->menu_item_parent ] )
80
			) {
81
				$_return[ $item->menu_item_parent ]->add_child( $item );
82
				unset( $_return[ $item_id ] );
83
			}
84
		}
85
86
		$this->items = $_return;
87
	}
88
89
	/**
90
	 * Returns first menu id or false if there are no menus.
91
	 *
92
	 * @return int|bool
93
	 */
94
	protected function get_first_menu_id() {
95
		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
96
97
		if ( is_array( $menus ) && count( $menus ) ) {
98
			if ( isset( $menus[0]->term_id ) ) {
99
				return $menus[0]->term_id;
100
			}
101
		}
102
103
		return false;
104
	}
105
106
	/**
107
	 * Performs menu id lookup inside navigation Menus.
108
	 *
109
	 * @param  array      $locations locations that are returned by get_nav_menu_locations().
110
	 * @param  int|string $arg navigation id.
111
	 * @return int
112
	 */
113
	protected function get_locations_menu_id( $locations, $arg ) {
114
		if ( is_numeric( $arg ) ) {
115
			$arg = array_search( $arg, $locations );
116
		}
117
118
		if ( isset( $locations[ $arg ] ) ) {
119
			$menu_id = $locations[ $arg ];
120
121
			return $menu_id;
122
		}
123
	}
124
125
	/**
126
	 * Checks if the provided menu id exists.
127
	 *
128
	 * @param int $menu_id Menu ID.
129
	 *
130
	 * @return int|boolean
131
	 */
132
	protected function check_menu_id( $menu_id ) {
133
		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
134
135
		if ( is_array( $menus ) && count( $menus ) ) {
136
			foreach ( $menus as $menu ) {
137
				if ( absint( $menu->term_id ) === absint( $menu_id ) ) {
138
					return $menu_id;
139
				}
140
			}
141
		}
142
143
		return false;
144
	}
145
146
	/**
147
	 * Returns menu id by menu name/slug.
148
	 *
149
	 * @param string $slug Menu's name.
150
	 *
151
	 * @return int|bool
152
	 */
153
	protected function get_menu_id_by_name( $slug = null ) {
154
		if ( $slug && is_string( $slug ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $slug of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
155
			if ( $menu_id = get_term_by( 'slug', $slug, 'nav_menu' ) ) {
156
				return $menu_id;
157
			}
158
159
			if ( $menu_id = get_term_by( 'name', $slug, 'nav_menu' ) ) {
160
				return $menu_id;
161
			}
162
		}
163
164
		return false;
165
	}
166
167
	/**
168
	 * Returns menu name by menu id.
169
	 *
170
	 * @return int|bool
171
	 */
172
	protected function get_menu_name_by_id() {
173
		$menu_obj = wp_get_nav_menu_object( $this->ID );
174
175
		if ( $menu_obj ) {
176
			return $menu_obj->name;
177
		}
178
179
		return false;
180
	}
181
182
183
	/**
184
	 * Returns menu items.
185
	 *
186
	 * @return array
187
	 */
188
	public function get_items() {
189
		return $this->items;
190
	}
191
}
192