Issues (3887)

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/LayoutBundle/Layout/Block/Type/FormType.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 Oro\Bundle\LayoutBundle\Layout\Block\Type;
4
5
use Symfony\Component\Form\FormView;
6
use Symfony\Component\OptionsResolver\Options;
7
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
8
9
use Oro\Component\Layout\Block\Type\ContainerType;
10
use Oro\Component\Layout\BlockView;
11
use Oro\Component\Layout\BlockInterface;
12
use Oro\Component\Layout\BlockBuilderInterface;
13
14
use Oro\Bundle\LayoutBundle\Layout\Form\ConfigurableFormAccessorInterface;
15
use Oro\Bundle\LayoutBundle\Layout\Form\FormLayoutBuilderInterface;
16
17
/**
18
 * This block type is responsible to build the layout for a Symfony's form object.
19
 * Naming convention:
20
 *  field id = $options['form_field_prefix'] + field path (path separator is replaced with colon (:))
21
 *      for example: form_firstName or form_address:city  where 'form_' is the prefix
22
 *  group id = $options['form_group_prefix'] + group name
23
 *      for example: form:group_myGroup where 'form:group_' is the prefix
24
 */
25
class FormType extends AbstractFormType
26
{
27
    const NAME = 'form';
28
29
    /** @var FormLayoutBuilderInterface */
30
    protected $formLayoutBuilder;
31
32
    /**
33
     * @param FormLayoutBuilderInterface $formLayoutBuilder
34
     */
35
    public function __construct(FormLayoutBuilderInterface $formLayoutBuilder)
36
    {
37
        $this->formLayoutBuilder = $formLayoutBuilder;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function setDefaultOptions(OptionsResolverInterface $resolver)
44
    {
45
        parent::setDefaultOptions($resolver);
46
        $resolver->setDefaults(
47
            [
48
                // example: ['jobTitle', 'user.lastName']
49
                'preferred_fields'  => [],
50
                // example:
51
                // [
52
                //   'general'    => [
53
                //     'title'  => 'General Info',
54
                //     'fields' => ['user.firstName', 'user.lastName']
55
                //   ],
56
                //   'additional'    => [
57
                //     'title'   => 'Additional Info',
58
                //     'default' => true
59
                //   ]
60
                // ]
61
                'groups'            => [],
62
                'form_prefix'       => function (Options $options, $value) {
63
                    return null === $value ? $options['form_name'] : $value;
64
                },
65
                'form_field_prefix' => function (Options $options, $value) {
66
                    return null === $value ? $options['form_prefix'] . '_' : $value;
67
                },
68
                'form_group_prefix' => function (Options $options, $value) {
69
                    return null === $value ? $options['form_prefix'] . ':group_' : $value;
70
                },
71
                'split_to_fields'   => false
72
            ]
73
        );
74
        $resolver
75
            ->setOptional(['form_data']);
76
77
        $resolver->setAllowedTypes(
78
            [
79
                'preferred_fields'  => 'array',
80
                'groups'            => 'array',
81
                'form_prefix'       => 'string',
82
                'form_field_prefix' => 'string',
83
                'form_group_prefix' => 'string',
84
                'split_to_fields'   => 'bool',
85
            ]
86
        );
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function buildBlock(BlockBuilderInterface $builder, array $options)
93
    {
94
        $formAccessor = $this->getFormAccessor($builder->getContext(), $options);
95
        if ($options['split_to_fields']) {
96
            $this->formLayoutBuilder->build($formAccessor, $builder, $options);
97
        }
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function buildView(BlockView $view, BlockInterface $block, array $options)
104
    {
105
        $view->vars['form_data'] = isset($options['form_data']) ? $options['form_data'] : null;
106
107
        $formAccessor = $this->getFormAccessor($block->getContext(), $options);
108
        if ($formAccessor instanceof ConfigurableFormAccessorInterface) {
109
            $formAccessor->setFormData($view->vars['form_data']);
110
        }
111
        $formView = $formAccessor->getView();
112
        if (!isset($view->vars['class_prefix'])) {
113
            $view->vars['class_prefix'] = $block->getId();
114
        }
115
        $this->setClassPrefixToFormView($formView, $view->vars['class_prefix']);
116
        $view->vars['form'] = $formView;
117
118
        $view->vars['split_to_fields'] = $options['split_to_fields'];
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function finishView(BlockView $view, BlockInterface $block, array $options)
125
    {
126
        if (!$options['split_to_fields']) {
127
            return;
128
        }
129
        $formAccessor = $this->getFormAccessor($block->getContext(), $options);
130
131
        // prevent form fields rendering by form_rest() method,
132
        // if the corresponding layout block has been removed
133
        foreach ($formAccessor->getProcessedFields() as $formFieldPath => $blockId) {
134
            if (isset($view[$blockId])) {
135
                $this->checkExistingFieldView($view, $view[$blockId], $formFieldPath);
136
                continue;
137
            }
138
            if (isset($view->blocks[$blockId])) {
139
                $this->checkExistingFieldView($view, $view->blocks[$blockId], $formFieldPath);
140
                continue;
141
            }
142
143
            $this->getFormFieldView($view, $formFieldPath)->setRendered();
144
        }
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    public function getName()
151
    {
152
        return self::NAME;
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function getParent()
159
    {
160
        return ContainerType::NAME;
161
    }
162
163
    /**
164
     * Returns form field view
165
     *
166
     * @param BlockView $view
167
     * @param string    $formFieldPath
168
     *
169
     * @return FormView
170
     */
171
    protected function getFormFieldView(BlockView $view, $formFieldPath)
172
    {
173
        /** @var FormView $form */
174
        $form = $view->vars['form'];
175
        foreach (explode('.', $formFieldPath) as $field) {
176
            $form = $form[$field];
177
        }
178
179
        return $form;
180
    }
181
182
    /**
183
     * Checks whether an existing field view is the view created in buildBlock method,
184
     * and if it is another view mark the corresponding form field as rendered
185
     *
186
     * @param BlockView $view
187
     * @param BlockView $childView
188
     * @param string    $formFieldPath
189
     */
190
    protected function checkExistingFieldView(BlockView $view, BlockView $childView, $formFieldPath)
191
    {
192
        if (!isset($childView->vars['form'])) {
193
            $this->getFormFieldView($view, $formFieldPath)->setRendered();
194
        } else {
195
            $formFieldView = $this->getFormFieldView($view, $formFieldPath);
196
            if ($childView->vars['form'] !== $formFieldView) {
197
                $formFieldView->setRendered();
198
            }
199
        }
200
    }
201
202
    /**
203
     * Sets class_prefix to FormView and it's childs recursively
204
     *
205
     * @param FormView $formView
206
     * @param string   $classPrefix
207
     */
208
    protected function setClassPrefixToFormView(FormView $formView, $classPrefix)
209
    {
210
        $formView->vars['class_prefix'] = $classPrefix;
211
212
        if (empty($formView->children) && !isset($formView->vars['prototype'])) {
213
            return;
214
        }
215
        foreach ($formView->children as $child) {
216
            $this->setClassPrefixToFormView($child, $classPrefix);
217
        }
218
        if (isset($formView->vars['prototype'])) {
219
            $this->setClassPrefixToFormView($formView->vars['prototype'], $classPrefix);
0 ignored issues
show
$formView->vars['prototype'] is of type string, but the function expects a object<Symfony\Component\Form\FormView>.

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...
220
        }
221
    }
222
}
223