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.

EventListener/NodeIndexUpdateEventListener.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\NodeSearchBundle\EventListener;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Event\LifecycleEventArgs;
7
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
8
use Kunstmaan\NodeBundle\Entity\StructureNode;
9
use Kunstmaan\NodeBundle\Event\NodeEvent;
10
use Kunstmaan\NodeSearchBundle\Configuration\NodePagesConfiguration;
11
use Symfony\Component\DependencyInjection\ContainerInterface;
12
13
/**
14
 * EventListener which will be triggered when a Node has been updated in order to update its related documents
15
 * in the index
16
 */
17
class NodeIndexUpdateEventListener implements NodeIndexUpdateEventListenerInterface
18
{
19
    /** @var ContainerInterface */
20
    private $container;
21
22
    /** @var EntityManagerInterface */
23
    private $em;
24
25
    /** @var NodePagesConfiguration */
26
    private $nodePagesConfiguration;
27
28
    /** @var array */
29
    private $entityChangeSet;
30
31 5
    public function __construct(/* NodePagesConfiguration */
32
        $nodePagesConfiguration, /* EntityManagerInterface */
33
        $em = null)
34
    {
35 5
        if ($nodePagesConfiguration instanceof ContainerInterface) {
36 1
            @trigger_error(sprintf('Passing the container as the first argument of "%s" is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Inject the "%s" service instead.', __CLASS__, 'kunstmaan_node_search.search_configuration.node'), E_USER_DEPRECATED);
37
38 1
            $this->container = $nodePagesConfiguration;
39 1
            $this->nodePagesConfiguration = $this->container->get('kunstmaan_node_search.search_configuration.node');
40
41 1
            if (null === $em) {
42
                $this->em = $this->container->get('doctrine.orm.default_entity_manager');
43
            }
44
45 1
            return;
46
        }
47
48 4
        if (!($em instanceof EntityManagerInterface)) {
49
            @trigger_error(sprintf('Passing null or something other than an entitymanagerinterface as the second argument of "%s" is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Inject the "%s" service instead.', __CLASS__, 'doctrine.orm.default_entity_manager'), E_USER_DEPRECATED);
50
        }
51
52 4
        $this->nodePagesConfiguration = $nodePagesConfiguration;
53 4
        $this->em = $em;
54 4
    }
55
56
    /**
57
     * @param LifecycleEventArgs $args
58
     */
59
    public function preUpdate(LifecycleEventArgs $args)
60
    {
61
        if ($args->getObject() instanceof NodeTranslation) {
62
            // unfortunately we have to keep a state to see what has changed
63
            $this->entityChangeSet = [
64
                'nodeTranslationId' => $args->getObject()->getId(),
65
                'changeSet' => $args->getEntityManager()->getUnitOfWork()->getEntityChangeSet($args->getObject()),
66
            ];
67
        }
68
    }
69
70
    /**
71
     * @param NodeEvent $event
72
     */
73
    public function onPostPublish(NodeEvent $event)
74
    {
75
        $this->index($event);
76
    }
77
78
    /**
79
     * @param NodeEvent $event
80
     */
81 4
    public function onPostPersist(NodeEvent $event)
82
    {
83
        $reIndexChildren = (
84 4
            !\is_null($this->entityChangeSet)
85 4
            && $this->entityChangeSet['nodeTranslationId'] == $event->getNodeTranslation()->getId()
86 4
            && isset($this->entityChangeSet['changeSet']['url'])
87
        );
88 4
        $this->index($event, $reIndexChildren);
89 4
    }
90
91
    /**
92
     * @param NodeEvent $event
93
     * @param bool      $reIndexChildren
94
     */
95 4
    private function index(NodeEvent $event, $reIndexChildren = false)
96
    {
97 4
        $nodeTranslation = $event->getNodeTranslation();
98
99 4
        if ($this->hasOfflineParents($nodeTranslation)) {
100 2
            return;
101
        }
102
103 2
        $this->nodePagesConfiguration->indexNodeTranslation($nodeTranslation, true);
104
105 2
        if ($reIndexChildren) {
106
            $this->nodePagesConfiguration->indexChildren($event->getNode(), $nodeTranslation->getLang());
107
        }
108 2
    }
109
110
    /**
111
     * @param NodeEvent $event
112
     */
113
    public function onPostDelete(NodeEvent $event)
114
    {
115
        $this->delete($event);
116
    }
117
118
    /**
119
     * @param NodeEvent $event
120
     */
121
    public function onPostUnPublish(NodeEvent $event)
122
    {
123
        $this->delete($event);
124
    }
125
126
    /**
127
     * @param NodeEvent $event
128
     */
129
    public function delete(NodeEvent $event)
130
    {
131
        $this->nodePagesConfiguration->deleteNodeTranslation($event->getNodeTranslation());
132
    }
133
134
    /**
135
     * @param $nodeTranslation
136
     *
137
     * @return bool
138
     */
139 4
    private function hasOfflineParents(NodeTranslation $nodeTranslation)
140
    {
141 4
        $lang = $nodeTranslation->getLang();
142 4
        $node = $nodeTranslation->getNode();
143 4
        if (null !== $this->em) {
144 4
            $em = $this->em;
145
        } else {
146
            $lang = $nodeTranslation->getLang();
147
            foreach ($nodeTranslation->getNode()->getParents() as $node) {
148
                $nodeNT = $node->getNodeTranslation($lang, true);
149
                if ($nodeNT && !$nodeNT->isOnline()) {
150
                    return true;
151
                }
152
            }
153
154
            return false;
155
        }
156
157 4
        foreach ($node->getParents() as $parent) {
158 4
            $parentNodeTranslation = $parent->getNodeTranslation($lang, true);
159 4
            if (null === $parentNodeTranslation) {
160
                continue;
161
            }
162 4
            $parentRef = $parentNodeTranslation->getRef($em);
0 ignored issues
show
$em of type object<Doctrine\ORM\EntityManagerInterface> is not a sub-type of object<Doctrine\ORM\EntityManager>. It seems like you assume a concrete implementation of the interface Doctrine\ORM\EntityManagerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
163
            // Continue looping unless we find an offline page that is not a StructureNode
164 4
            if ($parentRef instanceof StructureNode || $parentNodeTranslation->isOnline()) {
165 3
                continue;
166
            }
167
168 2
            return true;
169
        }
170
171 2
        return false;
172
    }
173
}
174