Issues (3885)

Security Analysis    not enabled

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.

core/src/Support/Menu.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 namespace EvolutionCMS\Support;
2
3
/**
4
 * menu->Build('id','parent','name','link','alt','onclick','permission','target','divider 1/0','menuindex')
5
 */
6
7
use EvolutionCMS\Interfaces\MenuInterface;
8
9
class Menu implements MenuInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    public $defaults = array();
15
    /**
16
     * @var
17
     */
18
    public $menu;
19
    /**
20
     * @var
21
     */
22
    public $output;
23
24
    /**
25
     * @param $menu
26
     * @param array $setting
27
     * @param bool $show
28
     */
29
    public function build($menu, $setting = array(), $show = true)
30
    {
31
        $this->defaults['outerClass'] = 'nav';
32
        $this->defaults['parentClass'] = 'dropdown';
33
        $this->defaults['parentLinkClass'] = 'dropdown-toggle';
34
        $this->defaults['parentLinkAttr'] = 'data-toggle="dropdown"';
35
        $this->defaults['parentLinkIn'] = '<b class="caret"></b>';
36
        $this->defaults['innerClass'] = 'subnav';
37
38
        $this->defaults = $setting + $this->defaults;
39
        $this->structurise($menu);
40
        $this->output = $this->drawSub('main', 0);
41
        if ($show) {
42
            echo $this->output;
43
        } else {
44
            return $this->output;
45
        }
46
    }
47
48
    /**
49
     * @param array $menu
50
     */
51
    public function structurise($menu)
52
    {
53
        $new = array();
54
        foreach ($menu as $key => $row) {
55
            $data[$key] = $row[9];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
56
        }
57
58
        array_multisort($data, SORT_ASC, $menu);
59
60
        foreach ($menu as $key => $value) {
61
            $new[$value[1]][] = $value;
62
        }
63
64
        $this->menu = $new;
65
    }
66
67
    /**
68
     * @param int $parentid
69
     * @param int $level
70
     * @return string
71
     */
72
    public function drawSub($parentid, $level)
73
    {
74
        $modx = evolutionCMS();
75
76
        $output = '';
77
78
        if (isset($this->menu[$parentid])) {
79
80
            $ph = array();
81
            $countChild = 0;
82
            $itemTpl = '
83
			<li id="[+id+]" class="[+li_class+]"><a href="[+href+]" alt="[+alt+]" target="[+target+]" onclick="[+onclick+]"[+a_class+] [+LinkAttr+]>[+itemName+]</a>[+DrawSub+]</li>';
84
            $outerTpl = '<ul id="[+id+]" class="[+class+]">[+output+]</ul>';
85
            foreach ($this->menu[$parentid] as $key => $value) {
86
                if ($value[6] !== '') {
87
                    $permissions = explode(',', $value[6]);
88
                    foreach ($permissions as $val) {
89
                        if (!$modx->hasPermission($val)) {
90
                            continue;
91
                        }
92
                    }
93
                }
94
95
                $countChild++;
96
                $id = $value[0];
97
                $ph['id'] = $id;
98
                $ph['li_class'] = $this->getItemClass($id) . $value[10];
99
                $ph['href'] = $value[3];
100
                $ph['alt'] = $value[4];
101
                $ph['target'] = $value[7];
102
                $ph['onclick'] = $value[5];
103
                $ph['a_class'] = $this->getLinkClass($id);
104
                $ph['LinkAttr'] = $this->getLinkAttr($id);
105
                $ph['itemName'] = $value[2] . $this->getItemName($id);
106
107
                $ph['DrawSub'] = '';
108
109
                if (isset($this->menu[$id])) {
110
                    $level++;
111
                    $ph['DrawSub'] = $this->drawSub($id, $level);
112
                    $level--;
113
                    // Optional buttons
114
                } else {
115
                    if (isset($value[11]) && !empty($value[11])) {
116
                        $optionalButton = '';
117
                        if (is_array($value[11])) {
118
                            foreach ($value[11] as $opt) {
119
                                $optionalButton .= sprintf('<%s href="%s" class="%s" onclick="%s" title="%s">%s</%s>',
120
                                    $opt[0], $opt[1], $opt[2], $opt[3], $opt[4], $opt[5], $opt[0]);
121
                            }
122
                        } else {
123
                            $opt = $value[11];
124
                            $optionalButton = sprintf('<%s href="%s" class="%s" onclick="%s" title="%s">%s</%s>',
125
                                $opt[0], $opt[1], $opt[2], $opt[3], $opt[4], $opt[5], $opt[0]);
126
                        }
127
                        $ph['DrawSub'] = $optionalButton;
128
                    }
129
                }
130
131
                $output .= $modx->parseText($itemTpl, $ph);
132
            }
133
134
            $ph = array();
135
            if ($countChild > 0) {
136
                $ph['id'] = $level == 0 ? $this->defaults['outerClass'] : '';
137
                $ph['class'] = $level == 0 ? $this->defaults['outerClass'] : $this->defaults['innerClass'];
138
                $ph['output'] = $output;
139
                $output = $modx->parseText($outerTpl, $ph);
140
            }
141
        }
142
143
        return $output;
144
    }
145
146
    /**
147
     * @param int $id
148
     * @return string
149
     */
150
    public function getLinkClass($id)
151
    {
152
        if (isset($this->menu[$id])) {
153
            return ' class="' . $this->defaults['parentLinkClass'] . '"';
154
        } else {
155
            return '';
156
        }
157
    }
158
159
    /**
160
     * @param int $id
161
     * @return string
162
     */
163
    public function getLinkAttr($id)
164
    {
165
        if (isset($this->menu[$id])) {
166
            return $this->defaults['parentLinkAttr'];
167
        } else {
168
            return '';
169
        }
170
    }
171
172
    /**
173
     * @param int $id
174
     * @return string
175
     */
176
    public function getItemClass($id)
177
    {
178
        if (isset($this->menu[$id])) {
179
            return $this->defaults['parentClass'] . ' ';
180
        } else {
181
            return '';
182
        }
183
    }
184
185
    /**
186
     * @param int $id
187
     * @return string
188
     */
189
    public function getItemName($id)
190
    {
191
        if (isset($this->menu[$id])) {
192
            return $this->defaults['parentLinkIn'];
193
        } else {
194
            return '';
195
        }
196
    }
197
}
198