Issues (5)

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.

Twig/Extension/Menu/AbstractMenuTwigExtension.php (2 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
/*
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\AdminBSBBundle\Twig\Extension\Menu;
13
14
use Twig\Environment;
15
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension;
16
use WBW\Bundle\AdminBSBBundle\Twig\Extension\RendererTwigExtension;
17
use WBW\Bundle\CoreBundle\Component\Translation\BaseTranslatorInterface;
18
use WBW\Bundle\CoreBundle\Navigation\AbstractNavigationNode;
19
use WBW\Bundle\CoreBundle\Navigation\HeaderNode;
20
use WBW\Bundle\CoreBundle\Navigation\NavigationNode;
21
use WBW\Bundle\CoreBundle\Navigation\NavigationTree;
22
use WBW\Bundle\CoreBundle\Service\TranslatorTrait;
23
24
/**
25
 * Abstract multi level menu Twig extension.
26
 *
27
 * @author webeweb <https://github.com/webeweb/>
28
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Menu
29
 * @abstract
30
 */
31
abstract class AbstractMenuTwigExtension extends AbstractTwigExtension {
32
33
    use TranslatorTrait;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param Environment $twigEnvironment The Twig environment.
39
     * @param BaseTranslatorInterface $translator The translator.
40
     */
41
    public function __construct(Environment $twigEnvironment, $translator) {
42
        parent::__construct($twigEnvironment);
43
        $this->setTranslator($translator);
44
    }
45
46
    /**
47
     * Displays an AdminBSB  menu.
48
     *
49
     * @param NavigationTree $tree The navigation tree.
50
     * @return string Returns the Admin BSB menu.
51
     */
52
    protected function adminBSBMenu(NavigationTree $tree): string {
53
54
        $templates = [];
55
56
        foreach ($tree->getNodes() as $current) {
57
            $templates[] = $this->renderNode($current);
58
        }
59
60
        return implode("\n", $templates);
61
    }
62
63
    /**
64
     * Determines if a node is a menu toggle.
65
     *
66
     * @param NavigationNode $node
67
     * @return bool Returns true in case of success, false otherwise.
68
     */
69
    protected function isMenuToggle(NavigationNode $node): bool {
70
71
        foreach ($node->getNodes() as $current) {
72
73
            if (true === ($current instanceof NavigationNode) && true === $current->isDisplayable()) {
74
                return true;
75
            }
76
        }
77
78
        return false;
79
    }
80
81
    /**
82
     * Render an anchor.
83
     *
84
     * @param NavigationNode $node The navigation node.
85
     * @return string Returns the rendered anchor.
86
     */
87
    private function renderAnchor(NavigationNode $node): string {
88
89
        $attributes = [
90
            "href"   => $node->getUri(),
91
            "target" => $node->getTarget(),
92
        ];
93
94
        if ($this->isMenuToggle($node)) {
95
            $attributes["class"] = "menu-toggle";
96
        }
97
98
        $icon = $this->renderIcon($node);
99
        $span = $this->renderSpan($node);
100
101
        return static::coreHTMLElement("a", "\n${icon}{$span}", $attributes) . "\n";
102
    }
103
104
    /**
105
     * Render a dropdown.
106
     *
107
     * @param NavigationNode $node The navigation node.
108
     * @param array $items The items.
109
     * @return string Returns the rendered dropdown.
110
     */
111
    private function renderDropdown(NavigationNode $node, array $items): string {
0 ignored issues
show
The parameter $node is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
113
        $innerHTML = implode("\n", $items);
114
115
        $dropdown = static::coreHTMLElement("ul", "\n{$innerHTML}", ["class" => "ml-menu"]);
116
117
        return "{$dropdown}\n";
118
    }
119
120
    /**
121
     * Render an header node.
122
     *
123
     * @param HeaderNode $node The header node.
124
     * @return string Returns the rendered header node.
125
     */
126
    private function renderHeader(HeaderNode $node): string {
127
        return static::coreHTMLElement("li", $node->getLabel(), ["class" => "header"]);
128
    }
129
130
    /**
131
     * Render an icon.
132
     *
133
     * @param NavigationNode $node The navigation node.
134
     * @return string Returns the rendered icon.
135
     */
136
    private function renderIcon(NavigationNode $node): string {
137
        if (null === $node->getIcon()) {
138
            return "";
139
        }
140
        return RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $node->getIcon()) . "\n";
0 ignored issues
show
It seems like $this->getTwigEnvironment() can be null; however, renderIcon() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
141
    }
142
143
    /**
144
     * Render a navigation node.
145
     *
146
     * @param NavigationNode $node The navigation node.
147
     * @param int $level The level.
148
     * @return string Returns the rendered navigation node.
149
     */
150
    private function renderNavigation(NavigationNode $node, int $level = 0): string {
151
152
        $anchor = $this->renderAnchor($node);
153
154
        $attributes = true === $node->getActive() ? ["class" => "active"] : [];
155
156
        if (0 === $node->size()) {
157
            return static::coreHTMLElement("li", "\n{$anchor}", $attributes);
158
        }
159
160
        $items = [];
161
        foreach ($node->getNodes() as $current) {
162
            $items[] = $this->renderNode($current, $level + 1);
163
        }
164
165
        $dropdown = $this->renderDropdown($node, $items);
166
167
        return static::coreHTMLElement("li", "\n{$anchor}{$dropdown}", $attributes);
168
    }
169
170
    /**
171
     * Render a node.
172
     *
173
     * @param AbstractNavigationNode $node The node.
174
     * @param int $level The level.
175
     * @return string Returns the rendered node.
176
     */
177
    private function renderNode(AbstractNavigationNode $node, int $level = 0): string {
178
179
        if (false === $node->isDisplayable()) {
180
            return "";
181
        }
182
183
        if (true === ($node instanceof HeaderNode)) {
184
            return $this->renderHeader($node);
185
        }
186
187
        if (true === ($node instanceof NavigationNode)) {
188
            return $this->renderNavigation($node, $level);
189
        }
190
191
        return "";
192
    }
193
194
    /**
195
     * Render a span.
196
     *
197
     * @param NavigationNode $node The navigation node.
198
     * @return string Returns the rendered span.
199
     */
200
    private function renderSpan(NavigationNode $node): string {
201
202
        $innerHTML = null !== $node->getId() ? $this->translate($node->getLabel()) : "";
203
204
        return static::coreHTMLElement("span", $innerHTML) . "\n";
205
    }
206
207
    /**
208
     * Translate.
209
     *
210
     * @param string $id The translation id.
211
     * @return string Returns the translation in case of success, id otherwise.
212
     */
213
    private function translate(string $id): string {
214
215
        $core = $this->getTranslator()->trans($id, [], "WBWCoreBundle");
216
        if ($id !== $core) {
217
            return $core;
218
        }
219
220
        $bootstrap = $this->getTranslator()->trans($id, [], "WBWBootstrapBundle");
221
        if ($id !== $bootstrap) {
222
            return $bootstrap;
223
        }
224
225
        $adminBSB = $this->getTranslator()->trans($id, [], "WBWAdminBSBBundle");
226
        if ($id !== $adminBSB) {
227
            return $adminBSB;
228
        }
229
230
        return $this->getTranslator()->trans($id);
231
    }
232
}
233