Issues (243)

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.

src/Navigation/CNavbar.php (4 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 Anax\Navigation;
4
5
/**
6
 * Helper to create a navbar for sites by reading its configuration from file
7
 * and then applying some code while rendering the resultning navbar.
8
 *
9
 */
10
class CNavbar
11
{
12
    use \Anax\TConfigure,
13
        \Anax\DI\TInjectionAware;
14
15
16
17
    /**
18
     * Create a navigation bar / menu, with submenu.
19
     *
20
     * @return string with html for the menu.
21
     *
22
     * @link http://dbwebb.se/coachen/skapa-en-dynamisk-navbar-meny-med-undermeny-via-php
23
     */
24
    public function create()
25
    {
26
        // Keep default options in an array and merge with incoming options that can override the defaults.
27
        $default = array(
28
            'id'          => null,
29
            'class'       => null,
30
            'wrapper'     => 'nav',
31
            'create_url'  => function ($url) {
32
                return $url;
33
            },
34
        );
35
        $menu = array_replace_recursive($default, $this->config);
36
37
        // Create the ul li menu from the array, use an anonomous recursive function that returns an
38
        // array of values.
39
        $createMenu = function ($items, $callback) use (&$createMenu, $menu) {
40
            
41
            $html = null;
42
            $hasItemIsSelected = false;
43
44
            foreach ($items as $item) {
45
46
                // has submenu, call recursivly and keep track on if the submenu has a selected item in it.
47
                $submenu        = null;
48
                $selectedParent = null;
49
            
50
                if (isset($item['submenu'])) {
51
                    list($submenu, $selectedParent) = $createMenu($item['submenu']['items'], $callback);
52
                    $selectedParent = $selectedParent
53
                        ? "selected-parent "
54
                        : null;
55
                }
56
57
                // Check if the current menuitem is selected
58
                $selected = $callback($item['url'])
59
                    ? "selected "
60
                    : null;
61
                
62
                // Check if the menuitem is a parent of current page, /controller for /controller/action
63
                $isParent = null;
64
                if (isset($item['mark-if-parent-of']) && $item['mark-if-parent-of'] == true) {
65
                    $isParent = $menu['is_parent']($item['mark-if-parent-of'])
66
                        ? "is-parent "
67
                        : null;
68
                }
69
                
70
                // Is there a class set for this item, then use it
71
                $class = isset($item['class']) && ! is_null($item['class'])
72
                    ? $item['class']
73
                    : null;
74
75
                // Prepare the class-attribute, if used
76
                $class = ($selected || $selectedParent || $isParent || $class)
0 ignored issues
show
Bug Best Practice introduced by
The expression $selected 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...
Bug Best Practice introduced by
The expression $selectedParent 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...
Bug Best Practice introduced by
The expression $isParent 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...
77
                    ? " class='{$selected}{$selectedParent}{$isParent}{$class}' "
78
                    : null;
79
80
                // Add the menu item
81
                $url = $menu['create_url']($item['url']);
82
                $html .= "\n<li{$class}><a href='{$url}' title='{$item['title']}'>{$item['text']}</a>{$submenu}</li>\n";
83
                
84
                // To remember there is selected children when going up the menu hierarchy
85
                if ($selected) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $selected 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...
86
                    $hasItemIsSelected = true;
87
                }
88
            }
89
90
            // Return the menu
91
            return array("\n<ul>$html</ul>\n", $hasItemIsSelected);
92
        };
93
94
        // Call the anonomous function to create the menu, and submenues if any.
95
        list($html) = $createMenu($menu['items'], $menu['callback']);
96
97
98
        // Set the id & class element, only if it exists in the menu-array
99
        $id      = isset($menu['id'])    ? " id='{$menu['id']}'"       : null;
100
        $class   = isset($menu['class']) ? " class='{$menu['class']}'" : null;
101
        $wrapper = $menu['wrapper'];
102
103
        return "\n<{$wrapper}{$id}{$class}>{$html}</{$wrapper}>\n";
104
    }
105
}
106