Issues (1704)

Branch: master

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.

Resolver/BaseWidgetContentResolver.php (7 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 Victoire\Bundle\WidgetBundle\Resolver;
4
5
use Doctrine\ORM\EntityManager;
6
use Symfony\Component\PropertyAccess\PropertyAccess;
7
use Symfony\Component\PropertyAccess\PropertyAccessor;
8
use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity;
9
use Victoire\Bundle\APIBusinessEntityBundle\Resolver\APIBusinessEntityResolver;
10
use Victoire\Bundle\QueryBundle\Helper\QueryHelper;
11
use Victoire\Bundle\WidgetBundle\Model\Widget;
12
13
class BaseWidgetContentResolver
0 ignored issues
show
Missing class doc comment
Loading history...
14
{
15
    /**
16
     * @var QueryHelper
17
     */
18
    protected $queryHelper;
19
20
    /**
21
     * @var EntityManager
22
     */
23
    protected $entityManager;
24
25
    /**
26
     * @var APIBusinessEntityResolver
27
     */
28
    protected $apiResolver;
29
30
    /**
31
     * Get the static content of the widget.
32
     *
33
     * @param Widget $widget
34
     *
35
     * @return string
36
     */
37
    public function getWidgetStaticContent(Widget $widget)
38
    {
39
        $reflect = new \ReflectionClass($widget);
40
        $widgetProperties = $reflect->getProperties();
41
        $parameters = ['widget' => $widget];
42
        $accessor = PropertyAccess::createPropertyAccessor();
43
44
        foreach ($widgetProperties as $property) {
45
            if (!$property->isStatic()) {
46
                $value = $accessor->getValue($widget, $property->getName());
47
                $parameters[$property->getName()] = $value;
48
            }
49
        }
50
51
        return $parameters;
52
    }
53
54
    /**
55
     * Get the business entity content.
56
     *
57
     * @param Widget $widget
58
     *
59
     * @return string
60
     */
61 View Code Duplication
    public function getWidgetBusinessEntityContent(Widget $widget)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $entity = $widget->getEntity();
64
        $parameters = $this->getWidgetStaticContent($widget);
65
66
        $this->populateParametersWithWidgetFields($widget, $entity, $parameters);
67
68
        return $parameters;
69
    }
70
71
    /**
72
     * Get the content of the widget by the entity linked to it.
73
     *
74
     * @param Widget $widget
75
     *
76
     * @return string
77
     */
78 View Code Duplication
    public function getWidgetEntityContent(Widget $widget)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $entity = $widget->getEntity();
81
82
        $parameters = $this->getWidgetStaticContent($widget);
83
84
        $this->populateParametersWithWidgetFields($widget, $entity, $parameters);
85
86
        return $parameters;
87
    }
88
89
    /**
90
     * Get the content of the widget for the query mode.
91
     *
92
     * @param Widget $widget
93
     *
94
     * @return string
95
     */
96
    public function getWidgetQueryContent(Widget $widget)
97
    {
98
        $parameters = $this->getWidgetStaticContent($widget);
99
100
        if (APIBusinessEntity::TYPE === $widget->getBusinessEntity()->getType()) {
101
            $entity = $this->apiResolver->getBusinessEntities($widget->getBusinessEntity());
102
        } else {
103
            $entity = $this->getWidgetQueryBuilder($widget)
104
                            ->setMaxResults(1)
105
                            ->getQuery()
106
                            ->getOneOrNullResult();
107
        }
108
109
        $this->populateParametersWithWidgetFields($widget, $entity, $parameters);
110
111
        return $parameters;
112
    }
113
114
    /**
115
     * Get the widget query result.
116
     *
117
     * @param Widget $widget The widget
118
     *
119
     * @return \Doctrine\ORM\QueryBuilder The list of entities
120
     */
121
    public function getWidgetQueryBuilder(Widget $widget)
122
    {
123
        //get the base query
124
        $itemsQueryBuilder = $this->queryHelper->getQueryBuilder($widget, $this->entityManager);
0 ignored issues
show
$widget is of type object<Victoire\Bundle\WidgetBundle\Model\Widget>, but the function expects a object<Victoire\Bundle\Q...VictoireQueryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
125
126
        // Filter only visibleOnFront
127
        $itemsQueryBuilder->andWhere('main_item.visibleOnFront = true');
128
129
        //add the query of the widget
130
        return $this->queryHelper->buildWithSubQuery($widget, $itemsQueryBuilder, $this->entityManager);
0 ignored issues
show
$widget is of type object<Victoire\Bundle\WidgetBundle\Model\Widget>, but the function expects a object<Victoire\Bundle\Q...VictoireQueryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
131
    }
132
133
    protected function populateParametersWithWidgetFields(Widget $widget, $entity, &$parameters)
134
    {
135
        $fields = $widget->getFields();
136
        //parse the field
137
        foreach ($fields as $widgetField => $field) {
138
            //get the value of the field
139
            if (null !== $entity) {
140
                $attributeValue = null;
141
                if (null !== $field) {
142
                    $accessor = new PropertyAccessor();
143
                    $attributeValue = $accessor->getValue($entity, $field);
144
                }
145
            } else {
146
                $attributeValue = $widget->getBusinessEntityName().' -> '.$field;
147
            }
148
149
            $parameters[$widgetField] = $attributeValue;
150
        }
151
152
        $widget->setEntity($entity);
153
    }
154
155
    /**
156
     * @param QueryHelper $queryHelper
157
     */
158
    public function setQueryHelper(QueryHelper $queryHelper)
0 ignored issues
show
Declare public methods first,then protected ones and finally private ones
Loading history...
159
    {
160
        $this->queryHelper = $queryHelper;
161
    }
162
163
    /**
164
     * @param EntityManager $entityManager
165
     */
166
    public function setEntityManager(EntityManager $entityManager)
0 ignored issues
show
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
167
    {
168
        $this->entityManager = $entityManager;
169
    }
170
171
    /**
172
     * @param APIBusinessEntityResolver $resolver
173
     */
174
    public function setApiBusinessEntityResolver(APIBusinessEntityResolver $resolver)
175
    {
176
        $this->apiResolver = $resolver;
177
    }
178
}
179