Issues (7)

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/Menu.php (5 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
namespace Spatie\Menu\Laravel;
4
5
use Illuminate\Contracts\Auth\Access\Gate;
6
use Illuminate\Contracts\Support\Htmlable;
7
use Illuminate\Support\Traits\Macroable;
8
use Spatie\Menu\Item;
9
use Spatie\Menu\Menu as BaseMenu;
10
11
class Menu extends BaseMenu implements Htmlable
12
{
13
    use Macroable;
14
15
    /**
16
     * Set all relevant children active based on the current request's URL.
17
     *
18
     * /, /about, /contact => request to /about will set the about link active.
19
     *
20
     * /en, /en/about, /en/contact => request to /en won't set /en active if the
21
     *                                request root is set to /en.
22
     *
23
     * @param string $requestRoot If the link's URL is an exact match with the
24
     *                            request root, the link won't be set active.
25
     *                            This behavior is to avoid having home links
26
     *                            active on every request.
27
     *
28
     * @return $this
29
     */
30
    public function setActiveFromRequest(string $requestRoot = '/')
31
    {
32
        return $this->setActive(app('request')->url(), $requestRoot);
33
    }
34
35
    /**
36
     * @param string $path
37
     * @param string $text
38
     * @param mixed $parameters
39
     * @param bool|null $secure
40
     *
41
     * @return $this
42
     */
43
    public function url(string $path, string $text, $parameters = [], $secure = null)
44
    {
45
        return $this->add(Link::toUrl($path, $text, $parameters, $secure));
46
    }
47
48
    /**
49
     * @param string|array $action
50
     * @param string $text
51
     * @param mixed $parameters
52
     * @param bool $absolute
53
     *
54
     * @return $this
55
     */
56
    public function action($action, string $text, $parameters = [], bool $absolute = true)
57
    {
58
        return $this->add(Link::toAction($action, $text, $parameters, $absolute));
59
    }
60
61
    /**
62
     * @param string $name
63
     * @param string $text
64
     * @param mixed $parameters
65
     * @param bool $absolute
66
     *
67
     * @return $this
68
     */
69
    public function route(string $name, string $text, $parameters = [], bool $absolute = true)
70
    {
71
        return $this->add(Link::toRoute($name, $text, $parameters, $absolute));
72
    }
73
74
    /**
75
     * @param string $name
76
     * @param array $data
77
     *
78
     * @return $this
79
     */
80
    public function view(string $name, array $data = [])
81
    {
82
        return $this->add(View::create($name, $data));
83
    }
84
85
    /**
86
     * @param bool $condition
87
     * @param string $path
88
     * @param string $text
89
     * @param array $parameters
90
     * @param bool|null $secure
91
     *
92
     * @return $this
93
     */
94
    public function urlIf($condition, string $path, string $text, array $parameters = [], $secure = null)
95
    {
96
        return $this->addIf($condition, Link::toUrl($path, $text, $parameters, $secure));
97
    }
98
99
    /**
100
     * @param bool $condition
101
     * @param string|array $action
102
     * @param string $text
103
     * @param array $parameters
104
     * @param bool $absolute
105
     *
106
     * @return $this
107
     */
108
    public function actionIf($condition, $action, string $text, array $parameters = [], bool $absolute = true)
109
    {
110
        return $this->addIf($condition, Link::toAction($action, $text, $parameters, $absolute));
111
    }
112
113
    /**
114
     * @param bool $condition
115
     * @param string $name
116
     * @param string $text
117
     * @param array $parameters
118
     * @param bool $absolute
119
     *
120
     * @return $this
121
     */
122
    public function routeIf($condition, string $name, string $text, array $parameters = [], bool $absolute = true)
123
    {
124
        return $this->addIf($condition, Link::toRoute($name, $text, $parameters, $absolute));
125
    }
126
127
    /**
128
     * @param $condition
129
     * @param string $name
130
     * @param array $data
131
     *
132
     * @return $this
133
     */
134
    public function viewIf($condition, string $name, array $data = null)
135
    {
136
        return $this->addIf($condition, View::create($name, $data));
0 ignored issues
show
It seems like $data defined by parameter $data on line 134 can also be of type null; however, Spatie\Menu\Laravel\View::create() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
137
    }
138
139
    /**
140
     * @param string|array $authorization
141
     * @param \Spatie\Menu\Item $item
142
     *
143
     * @return $this
144
     */
145
    public function addIfCan($authorization, Item $item)
146
    {
147
        $ablityArguments = is_array($authorization) ? $authorization : [$authorization];
148
        $ability = array_shift($ablityArguments);
149
150
        return $this->addIf(app(Gate::class)->allows($ability, $ablityArguments), $item);
151
    }
152
153
    /**
154
     * @param string|array $authorization
155
     * @param string $url
156
     * @param string $text
157
     *
158
     * @return $this
159
     */
160
    public function linkIfCan($authorization, string $url, string $text)
161
    {
162
        return $this->addIfCan($authorization, Link::to($url, $text));
163
    }
164
165
    /**
166
     * @param string|array $authorization
167
     * @param string $html
168
     *
169
     * @return \Spatie\Menu\Laravel\Menu
170
     */
171
    public function htmlIfCan($authorization, string $html)
172
    {
173
        return $this->addIfCan($authorization, Html::raw($html));
174
    }
175
176
    /**
177
     * @param string|array $authorization
178
     * @param callable|\Spatie\Menu\Menu|\Spatie\Menu\Item $header
179
     * @param callable|\Spatie\Menu\Menu|null $menu
180
     *
181
     * @return $this
182
     */
183
    public function submenuIfCan($authorization, $header, $menu = null)
184
    {
185
        [$authorization, $header, $menu] = $this->parseSubmenuIfCanArgs(...func_get_args());
186
187
        $menu = $this->createSubmenuMenu($menu);
0 ignored issues
show
It seems like $menu can also be of type null; however, Spatie\Menu\Menu::createSubmenuMenu() does only seem to accept callable, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
188
        $header = $this->createSubmenuHeader($header);
0 ignored issues
show
It seems like $header can also be of type callable; however, Spatie\Menu\Menu::createSubmenuHeader() does only seem to accept object<Spatie\Menu\Item>|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
189
190
        return $this->addIfCan($authorization, $menu->prependIf($header, $header));
0 ignored issues
show
$header is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
191
    }
192
193
    protected function parseSubmenuIfCanArgs($authorization, ...$args): array
194
    {
195
        return array_merge([$authorization], $this->parseSubmenuArgs($args));
196
    }
197
198
    /**
199
     * @param string|array $authorization
200
     * @param string $path
201
     * @param string $text
202
     * @param array $parameters
203
     * @param bool|null $secure
204
     *
205
     * @return $this
206
     */
207
    public function urlIfCan($authorization, string $path, string $text, array $parameters = [], $secure = null)
208
    {
209
        return $this->addIfCan($authorization, Link::toUrl($path, $text, $parameters, $secure));
210
    }
211
212
    /**
213
     * @param string|array $authorization
214
     * @param string|array $action
215
     * @param string $text
216
     * @param array $parameters
217
     * @param bool $absolute
218
     *
219
     * @return $this
220
     */
221
    public function actionIfCan($authorization, $action, string $text, array $parameters = [], bool $absolute = true)
222
    {
223
        return $this->addIfCan($authorization, Link::toAction($action, $text, $parameters, $absolute));
224
    }
225
226
    /**
227
     * @param string|array $authorization
228
     * @param string $name
229
     * @param string $text
230
     * @param array $parameters
231
     * @param bool $absolute
232
     *
233
     * @return $this
234
     */
235
    public function routeIfCan($authorization, string $name, string $text, array $parameters = [], bool $absolute = true)
236
    {
237
        return $this->addIfCan($authorization, Link::toRoute($name, $text, $parameters, $absolute));
238
    }
239
240
    /**
241
     * @param $authorization
242
     * @param string $name
243
     * @param array $data
244
     *
245
     * @return $this
246
     * @internal param $condition
247
     */
248
    public function viewIfCan($authorization, string $name, array $data = null)
249
    {
250
        return $this->addIfCan($authorization, View::create($name, $data));
0 ignored issues
show
It seems like $data defined by parameter $data on line 248 can also be of type null; however, Spatie\Menu\Laravel\View::create() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
251
    }
252
253
    /**
254
     * @return string
255
     */
256
    public function toHtml(): string
257
    {
258
        return $this->render();
259
    }
260
}
261