Issues (116)

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.

Bundle/CoreBundle/Form/AbstractFormBuilder.php (1 issue)

Labels
Severity

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
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CoreBundle\Form;
14
15
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16
use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractContainerAware;
17
use WellCommerce\Bundle\CoreBundle\Doctrine\Repository\RepositoryInterface;
18
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
19
use WellCommerce\Bundle\CoreBundle\Form\DataTransformer\DataTransformerFactory;
20
use WellCommerce\Bundle\CoreBundle\Form\DataTransformer\RepositoryAwareDataTransformerInterface;
21
use WellCommerce\Component\Form\Dependencies\DependencyInterface;
22
use WellCommerce\Component\Form\Elements\ElementInterface;
23
use WellCommerce\Component\Form\Elements\FormInterface;
24
use WellCommerce\Component\Form\Event\FormEvent;
25
use WellCommerce\Component\Form\Filters\FilterInterface;
26
use WellCommerce\Component\Form\FormBuilderInterface;
27
use WellCommerce\Component\Form\Handler\FormHandlerInterface;
28
use WellCommerce\Component\Form\Resolver\FormResolverFactoryInterface;
29
use WellCommerce\Component\Form\Rules\RuleInterface;
30
31
/**
32
 * Class AbstractFormBuilder
33
 *
34
 * @author Adam Piotrowski <[email protected]>
35
 */
36
abstract class AbstractFormBuilder extends AbstractContainerAware implements FormBuilderInterface
37
{
38
    /**
39
     * @var FormResolverFactoryInterface
40
     */
41
    protected $resolverFactory;
42
    
43
    /**
44
     * @var FormHandlerInterface
45
     */
46
    protected $formHandler;
47
    
48
    /**
49
     * @var DataTransformerFactory
50
     */
51
    protected $dataTransformerFactory;
52
    
53
    /**
54
     * @var EventDispatcherInterface
55
     */
56
    protected $eventDispatcher;
57
    
58
    public function __construct(
59
        FormResolverFactoryInterface $resolverFactory,
60
        FormHandlerInterface $formHandler,
61
        DataTransformerFactory $dataTransformerFactory,
62
        EventDispatcherInterface $eventDispatcher
63
    ) {
64
        $this->resolverFactory        = $resolverFactory;
65
        $this->formHandler            = $formHandler;
66
        $this->dataTransformerFactory = $dataTransformerFactory;
67
        $this->eventDispatcher        = $eventDispatcher;
68
    }
69
    
70
    public function createForm($defaultData = null, array $options = []): FormInterface
71
    {
72
        $defaultOptions = ['name' => $this->getAlias()];
73
        $options        = array_merge($defaultOptions, $options);
74
        $form           = $this->getFormService($options);
75
        
76
        $this->buildForm($form);
77
        $this->dispatchFormEvent($form, $defaultData, FormEvent::FORM_PRE_INIT_EVENT);
78
        $this->formHandler->initForm($form, $defaultData);
79
        $this->dispatchFormEvent($form, $defaultData, FormEvent::FORM_POST_INIT_EVENT);
80
        
81
        return $form;
82
    }
83
    
84
    public function getElement(string $alias, array $options = []): ElementInterface
85
    {
86
        return $this->initService('element', $alias, $options);
87
    }
88
    
89
    public function getRule(string $alias, array $options = []): RuleInterface
90
    {
91
        return $this->initService('rule', $alias, $options);
92
    }
93
    
94
    public function getFilter(string $alias, array $options = []): FilterInterface
95
    {
96
        return $this->initService('filter', $alias, $options);
97
    }
98
    
99
    public function getDependency(string $alias, array $options = []): DependencyInterface
100
    {
101
        return $this->initService('dependency', $alias, $options);
102
    }
103
    
104
    public function getRepositoryTransformer(string $alias, RepositoryInterface $repository): RepositoryAwareDataTransformerInterface
105
    {
106
        /** @var RepositoryAwareDataTransformerInterface $transformer */
107
        $transformer = $this->dataTransformerFactory->createRepositoryTransformer($alias);
108
        $transformer->setRepository($repository);
109
        
110
        return $transformer;
111
    }
112
    
113
    protected function getFormService(array $options): FormInterface
114
    {
115
        return $this->getElement('form', $options);
116
    }
117
    
118
    abstract protected function buildForm(FormInterface $form);
119
    
120
    /**
121
     * Initializes a service by its type
122
     *
123
     * @param string $type
124
     * @param string $alias
125
     * @param array  $options
126
     *
127
     * @return object
128
     */
129
    protected function initService(string $type, string $alias, array $options)
130
    {
131
        $id      = $this->resolverFactory->resolve($type, $alias);
132
        $service = $this->get($id);
133
        
134
        $service->setOptions($options);
135
        
136
        return $service;
137
    }
138
    
139
    protected function dispatchFormEvent(FormInterface $form, EntityInterface $entity = null, string $name)
140
    {
141
        $eventName = sprintf('%s.%s', $this->getAlias(), $name);
142
        
143
        $this->eventDispatcher->dispatch($eventName, new FormEvent($this, $form, $entity));
0 ignored issues
show
It seems like $entity defined by parameter $entity on line 139 can also be of type object<WellCommerce\Bund...Entity\EntityInterface>; however, WellCommerce\Component\F...ormEvent::__construct() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
144
    }
145
    
146
    protected function addMetadataFieldset(FormInterface $form, RepositoryInterface $repository)
147
    {
148
        $metadata = $form->addChild($this->getElement('nested_fieldset', [
149
            'name'  => 'metadata',
150
            'label' => 'common.fieldset.meta',
151
        ]));
152
        
153
        $languageData = $metadata->addChild($this->getElement('language_fieldset', [
154
            'name'        => 'translations',
155
            'label'       => 'common.fieldset.translations',
156
            'transformer' => $this->getRepositoryTransformer('translation', $repository),
157
        ]));
158
        
159
        $languageData->addChild($this->getElement('text_field', [
160
            'name'  => 'meta.title',
161
            'label' => 'common.label.meta.title',
162
        ]));
163
        
164
        $languageData->addChild($this->getElement('text_field', [
165
            'name'  => 'meta.keywords',
166
            'label' => 'common.label.meta.keywords',
167
        ]));
168
        
169
        $languageData->addChild($this->getElement('text_area', [
170
            'name'  => 'meta.description',
171
            'label' => 'common.label.meta.description',
172
        ]));
173
    }
174
    
175
    protected function addShopsFieldset(FormInterface $form)
176
    {
177
        $shopsData = $form->addChild($this->getElement('nested_fieldset', [
178
            'name'  => 'shops_data',
179
            'label' => 'common.fieldset.shops',
180
        ]));
181
        
182
        $shopsData->addChild($this->getElement('multi_select', [
183
            'name'        => 'shops',
184
            'label'       => 'common.label.shops',
185
            'options'     => $this->get('shop.dataset.admin')->getResult('select'),
186
            'transformer' => $this->getRepositoryTransformer('collection', $this->get('shop.repository')),
187
        ]));
188
    }
189
}
190