Issues (12)

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.

Action/AbstractFormAction.php (3 issues)

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
namespace Pim\Bundle\CustomEntityBundle\Action;
4
5
use Pim\Bundle\CustomEntityBundle\Event\ActionEventManager;
6
use Pim\Bundle\CustomEntityBundle\Manager\Registry as ManagerRegistry;
7
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
8
use Symfony\Component\Form\Form;
9
use Symfony\Component\Form\FormFactoryInterface;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
use Symfony\Component\Routing\RouterInterface;
15
use Symfony\Component\Translation\TranslatorInterface;
16
17
/**
18
 * @author    Antoine Guigan <[email protected]>
19
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
20
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
21
 */
22
abstract class AbstractFormAction extends AbstractViewableAction
23
{
24
    /**
25
     * @var FormFactoryInterface
26
     */
27
    protected $formFactory;
28
29
    /**
30
     * @param ActionFactory        $actionFactory
31
     * @param ActionEventManager   $eventManager
32
     * @param ManagerRegistry      $managerRegistry
33
     * @param RouterInterface      $router
34
     * @param TranslatorInterface  $translator
35
     * @param EngineInterface      $templating
36
     * @param FormFactoryInterface $formFactory
37
     */
38
    public function __construct(
39
        ActionFactory $actionFactory,
40
        ActionEventManager $eventManager,
41
        ManagerRegistry $managerRegistry,
42
        RouterInterface $router,
43
        TranslatorInterface $translator,
44
        EngineInterface $templating,
45
        FormFactoryInterface $formFactory
46
    ) {
47
        parent::__construct($actionFactory, $eventManager, $managerRegistry, $router, $translator, $templating);
48
49
        $this->formFactory = $formFactory;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function setDefaultOptions(OptionsResolver $resolver)
56
    {
57
        parent::setDefaultOptions($resolver);
58
59
        $resolver->setRequired(['form_type', 'success_message']);
60
        $action = $this->actionFactory->getAction($this->configuration->getName(), 'index');
61
        $resolver->setDefaults(
62
            [
63
                'form_options'              => [],
64
                'template'                  => 'PimCustomEntityBundle:CustomEntity:form.html.twig',
65
                'redirect_route'            => $action->getRoute(),
66
                'redirect_route_parameters' => $action->getRouteParameters(),
67
                'save_options'              => []
68
            ]
69
        );
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function doExecute(Request $request)
76
    {
77
        $object = $this->getObject($request);
78
        $form = $this->createForm($request, $object);
79
        if ($request->isMethod('post')) {
80
            $form->submit($request);
81
            if ($form->isValid()) {
82
                $this->saveForm($request, $form);
83
                $this->addFlash($request, 'success', $this->options['success_message']);
84
85
                return $this->getRedirectResponse($object);
86
            }
87
        }
88
89
        return $this->renderResponse(
90
            $this->getTemplateVars($request, $form)
91
        );
92
    }
93
94
    /**
95
     * Saves the object
96
     *
97
     * @param Request       $request
98
     * @param FormInterface $form
99
     */
100
    protected function saveForm(Request $request, FormInterface $form)
101
    {
102
        $this->getManager()->save($form->getData(), $this->options['save_options']);
103
    }
104
105
    /**
106
     * Gets the variables that should be present on the template
107
     *
108
     * @param Request $request
109
     * @param Form    $form
110
     */
111
    protected function getTemplateVars(Request $request, FormInterface $form)
112
    {
113
        return [
114
            'form'       => $form->createView(),
115
            'formAction' => $this->getActionUrl($this->getType(), $form->getData())
116
        ];
117
    }
118
119
    /**
120
     * Returns the redirect response in case of success
121
     *
122
     * @param object $object
123
     *
124
     * @return RedirectResponse
125
     */
126
    protected function getRedirectResponse($object)
127
    {
128
        return new RedirectResponse($this->getRedirectPath($object));
129
    }
130
131
    /**
132
     * Returns the path to be redirected to in case of success
133
     *
134
     * @param object $object
135
     *
136
     * @return string
137
     */
138
    protected function getRedirectPath($object)
0 ignored issues
show
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
139
    {
140
        return $this->router->generate(
141
            $this->options['redirect_route'],
142
            $this->options['redirect_route_parameters']
143
        );
144
    }
145
146
    /**
147
     * Creates the form
148
     *
149
     * @param Request $request
150
     * @param object  $object
151
     *
152
     * @return Form
153
     */
154
    protected function createForm(Request $request, $object)
155
    {
156
        return $this->formFactory->create(
157
            $this->options['form_type'],
158
            $object,
159
            $this->getFormOptions($request, $object)
160
        );
161
    }
162
163
    /**
164
     * Returns the options of the form
165
     *
166
     * @param Request $request
167
     * @param object  $object
168
     *
169
     * @return array
170
     */
171
    protected function getFormOptions(Request $request, $object)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
172
    {
173
        return ['data_class' => $this->configuration->getEntityClass()] + $this->options['form_options'];
174
    }
175
176
    /**
177
     * Returns the object to use in the form
178
     *
179
     * @param Request $request
180
     *
181
     * @return object
182
     */
183
    abstract protected function getObject(Request $request);
184
}
185