Issues (3099)

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.

NodeBundle/Helper/Menu/PageMenuAdaptor.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
2
3
namespace Kunstmaan\NodeBundle\Helper\Menu;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
7
use Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface;
8
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
9
use Kunstmaan\AdminBundle\Helper\Menu\MenuItem;
10
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem;
11
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper;
12
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap;
13
use Kunstmaan\NodeBundle\Entity\Node;
14
use Kunstmaan\NodeBundle\Helper\NodeMenuItem;
15
use Kunstmaan\NodeBundle\Helper\PagesConfiguration;
16
use Symfony\Component\HttpFoundation\Request;
17
18
/**
19
 * The Page Menu Adaptor
20
 */
21
class PageMenuAdaptor implements MenuAdaptorInterface
22
{
23
    /**
24
     * @var EntityManagerInterface
25
     */
26
    private $em;
27
28
    /**
29
     * @var AclNativeHelper
30
     */
31
    private $aclNativeHelper;
32
33
    /**
34
     * @var array
35
     */
36
    private $treeNodes;
37
38
    /**
39
     * @var array
40
     */
41
    private $activeNodeIds;
42
43
    /**
44
     * @var PagesConfiguration
45
     */
46
    private $pagesConfiguration;
47
48
    /**
49
     * @var DomainConfigurationInterface
50
     */
51
    private $domainConfiguration;
52
53
    /**
54
     * @param EntityManagerInterface       $em                  The entity manager
55
     * @param AclNativeHelper              $aclNativeHelper     The acl helper
56
     * @param PagesConfiguration           $pagesConfiguration
57
     * @param DomainConfigurationInterface $domainConfiguration
58
     */
59
    public function __construct(
60
        EntityManagerInterface $em,
61
        AclNativeHelper $aclNativeHelper,
62
        PagesConfiguration $pagesConfiguration,
63
        DomainConfigurationInterface $domainConfiguration
64
    ) {
65
        $this->em = $em;
66
        $this->aclNativeHelper = $aclNativeHelper;
67
        $this->pagesConfiguration = $pagesConfiguration;
68
        $this->domainConfiguration = $domainConfiguration;
69
    }
70
71
    /**
72
     * In this method you can add children for a specific parent, but also
73
     * remove and change the already created children
74
     *
75
     * @param MenuBuilder $menu      The menu builder
76
     * @param MenuItem[]  &$children The children array that may be adapted
77
     * @param MenuItem    $parent    The parent menu item
78
     * @param Request     $request   The request
0 ignored issues
show
Should the type for parameter $request not be null|Request?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
79
     */
80
    public function adaptChildren(
81
        MenuBuilder $menu,
82
        array &$children,
83
        MenuItem $parent = null,
84
        Request $request = null
85
    ) {
86
        if (null === $parent) {
87
            $menuItem = new TopMenuItem($menu);
88
            $menuItem
89
                ->setRoute('KunstmaanNodeBundle_nodes')
90
                ->setUniqueId('pages')
91
                ->setLabel('pages.title')
92
                ->setParent($parent);
93
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
94
                $menuItem->setActive(true);
95
            }
96
            $children[] = $menuItem;
97
        } elseif (strncasecmp($request->attributes->get('_route'), 'KunstmaanNodeBundle_nodes', 25) === 0) {
98
            $treeNodes = $this->getTreeNodes(
99
                $request->getLocale(),
100
                PermissionMap::PERMISSION_VIEW,
101
                $this->aclNativeHelper,
102
                true
103
            );
104
            $activeNodeIds = $this->getActiveNodeIds($request);
105
106
            if (isset($treeNodes[0]) && 'KunstmaanNodeBundle_nodes' === $parent->getRoute()) {
107
                $this->processNodes(
108
                    $menu,
109
                    $children,
110
                    $treeNodes[0],
111
                    $parent,
112
                    $activeNodeIds
113
                );
114
            } elseif ('KunstmaanNodeBundle_nodes_edit' === $parent->getRoute()) {
115
                $parentRouteParams = $parent->getRouteParams();
116
                $parent_id = $parentRouteParams['id'];
117
                if (\array_key_exists($parent_id, $treeNodes)) {
118
                    $this->processNodes(
119
                        $menu,
120
                        $children,
121
                        $treeNodes[$parent_id],
122
                        $parent,
123
                        $activeNodeIds
124
                    );
125
                }
126
            }
127
        }
128
    }
129
130
    /**
131
     * Get the list of nodes that is used in the admin menu.
132
     *
133
     * @param string          $lang
134
     * @param string          $permission
135
     * @param AclNativeHelper $aclNativeHelper
136
     * @param bool            $includeHiddenFromNav
137
     *
138
     * @return array
139
     */
140
    private function getTreeNodes(
141
        $lang,
142
        $permission,
143
        AclNativeHelper $aclNativeHelper,
144
        $includeHiddenFromNav
145
    ) {
146
        if (null === $this->treeNodes) {
147
            $repo = $this->em->getRepository(Node::class);
148
            $this->treeNodes = [];
149
150
            $rootNode = $this->domainConfiguration->getRootNode();
151
152
            // Get all nodes that should be shown in the menu
153
            $allNodes = $repo->getAllMenuNodes(
154
                $lang,
155
                $permission,
156
                $aclNativeHelper,
157
                $includeHiddenFromNav,
158
                $rootNode
159
            );
160
            foreach ($allNodes as $nodeInfo) {
161
                $refEntityName = $nodeInfo['ref_entity_name'];
162
                if ($this->pagesConfiguration->isHiddenFromTree($refEntityName)) {
163
                    continue;
164
                }
165
                $parent_id = \is_null($nodeInfo['parent']) ? 0 : $nodeInfo['parent'];
166
                unset($nodeInfo['parent']);
167
                $this->treeNodes[$parent_id][] = $nodeInfo;
168
            }
169
            unset($allNodes);
170
        }
171
172
        return $this->treeNodes;
173
    }
174
175
    /**
176
     * Get an array with the id's off all nodes in the tree that should be
177
     * expanded.
178
     *
179
     * @param $request
180
     *
181
     * @return array
182
     */
183
    private function getActiveNodeIds($request)
184
    {
185
        if ((null === $this->activeNodeIds) && strncasecmp($request->attributes->get('_route'), 'KunstmaanNodeBundle_nodes_edit', 30) === 0) {
186
            $repo = $this->em->getRepository(Node::class);
187
188
            $currentNode = $repo->findOneById($request->attributes->get('id'));
189
            $parentNodes = $repo->getAllParents($currentNode);
190
            $this->activeNodeIds = [];
191
            foreach ($parentNodes as $parentNode) {
192
                $this->activeNodeIds[] = $parentNode->getId();
193
            }
194
        }
195
196
        return \is_null($this->activeNodeIds) ? [] : $this->activeNodeIds;
197
    }
198
199
    /**
200
     * @param MenuBuilder    $menu          The menu builder
201
     * @param MenuItem[]     &$children     The children array that may be
202
     *                                      adapted
203
     * @param NodeMenuItem[] $nodes         The nodes
204
     * @param MenuItem       $parent        The parent menu item
205
     * @param array          $activeNodeIds List with id's of all nodes that
206
     *                                      should be expanded in the tree
207
     */
208
    private function processNodes(
209
        MenuBuilder $menu,
210
        array &$children,
211
        array $nodes,
212
        MenuItem $parent = null,
213
        array $activeNodeIds
214
    ) {
215
        foreach ($nodes as $child) {
216
            $menuItem = new MenuItem($menu);
217
            $refName = $child['ref_entity_name'];
218
219
            $menuItem
220
                ->setRoute('KunstmaanNodeBundle_nodes_edit')
221
                ->setRouteParams(['id' => $child['id']])
222
                ->setUniqueId('node-'.$child['id'])
223
                ->setLabel($child['title'])
224
                ->setParent($parent)
225
                ->setOffline(!$child['online'] && !$this->pagesConfiguration->isStructureNode($refName))
226
                ->setHiddenFromNav($child['hidden'])
227
                ->setFolder($this->pagesConfiguration->isStructureNode($refName))
228
                ->setRole('page')
229
                ->setWeight($child['weight'])
230
                ->addAttributes(
231
                    [
232
                        'page' => [
233
                            'class' => $refName,
234
                            'children' => $this->pagesConfiguration->getPossibleChildTypes($refName),
235
                            'icon' => $this->pagesConfiguration->getIcon($refName) ?? ($this->pagesConfiguration->isHomePage($refName) ? 'fa fa-home' : null),
236
                        ],
237
                    ]
238
                );
239
240
            if (\in_array($child['id'], $activeNodeIds, false)) {
241
                $menuItem->setActive(true);
242
            }
243
            $children[] = $menuItem;
244
        }
245
    }
246
}
247