Issues (82)

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.

Handler/FormlyFormHandler.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
namespace Pgs\RestfonyBundle\Handler;
4
5
use JMS\Serializer\GenericSerializationVisitor;
6
use JMS\Serializer\GraphNavigator;
7
use JMS\Serializer\Handler\SubscribingHandlerInterface;
8
use JMS\Serializer\JsonSerializationVisitor;
9
use Symfony\Component\Form\Form;
10
use Symfony\Component\Form\FormError;
11
use Symfony\Component\Routing\RouterInterface;
12
use Symfony\Component\Translation\TranslatorInterface;
13
14
class FormlyFormHandler implements SubscribingHandlerInterface
15
{
16
    private $translator;
17
    /**
18
     * @var RouterInterface
19
     */
20
    private $router;
21
22 1
    public static function getSubscribingMethods()
23
    {
24 1
        $methods = array();
25 1
        foreach (array('xml', 'json', 'yml') as $format) {
26 1
            $methods[] = array(
27 1
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
28
                'type' => Form::class,
29 1
                'format' => $format,
30
            );
31 1
            $methods[] = array(
32 1
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
33
                'type' => FormError::class,
34 1
                'format' => $format,
35
            );
36
        }
37
38 1
        return $methods;
39
    }
40
41 5
    public function __construct(TranslatorInterface $translator, RouterInterface $router)
42
    {
43 5
        $this->translator = $translator;
44 5
        $this->router = $router;
45 5
    }
46
47 4
    public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form)
48
    {
49 4
        return $this->convertFormToArray($visitor, $form);
50
    }
51
52 4
    protected function getErrorMessage(FormError $error)
53
    {
54 4
        if (null !== $error->getMessagePluralization()) {
55 4
            return $this->translator->transChoice(
56 4
                $error->getMessageTemplate(),
57 4
                $error->getMessagePluralization(),
58 4
                $error->getMessageParameters(),
59 4
                'validators'
60
            );
61
        }
62
63 4
        return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators');
64
    }
65
66 4
    protected function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
67
    {
68 4
        $isRoot = null === $visitor->getRoot();
69
70 4
        $form = $errors = array();
71 4
        foreach ($data->getErrors() as $error) {
72 4
            $errors[] = $this->getErrorMessage($error);
73
        }
74
75 4
        if ($errors) {
76 4
            $form['errors'] = $errors;
77
        }
78
79 4
        $children = array();
80 4
        foreach ($data->all() as $child) {
81 4
            if ($child instanceof Form) {
82 4
                $children[$child->getName()] = $this->getConvertedChild($child, $visitor);
83
            }
84
        }
85
86 4
        if ($children) {
87 4
            $form['children'] = $children;
88
        }
89
90 4
        if ($isRoot) {
91 4
            $visitor->setRoot($form);
92
        }
93
94 4
        return $form;
95
    }
96
97
    /**
98
     * @param Form $child
99
     * @param GenericSerializationVisitor $visitor
100
     * @return array
101
     */
102 4
    private function getConvertedChild(Form $child, GenericSerializationVisitor $visitor)
103
    {
104 4
        if ($child->count()) {
105
            return [
106 4
                'type' => 'multifield',
107 4
                'key' => $child->getName(),
108
                'templateOptions' => [
109 4
                    'fields' => $this->convertFormToArray($visitor, $child),
110
                ],
111
            ];
112
        } else {
113
            $templateOptions = [
114 4
                'label' => $child->getConfig()->getOption('label'),
115 4
                'required' => $child->isRequired(),
116
            ];
117
118 4
            if ($child->getConfig()->getOption('custom-type')) {
119 1
                $textType = $child->getConfig()->getOption('custom-type');
120
            } else {
121 3
                $type = $child->getConfig()->getType();
122 3
                switch ($type->getName()) {
0 ignored issues
show
The method getName() does not seem to exist on object<Symfony\Component...olvedFormTypeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123 3
                    case 'rest_entity':
124 1
                        $textType = 'select-one';
125 1
                        $templateOptions['autocompleteUrl']
126 1
                            = $this->getAutocompleteUrl($child->getConfig()->getDataClass());
127 1
                        break;
128 2
                    case 'rest_collection':
129 1
                        $textType = 'select-multi';
130 1
                        $templateOptions['autocompleteUrl']
131 1
                            = $this->getAutocompleteUrl($child->getConfig()->getDataClass());
132 1
                        break;
133
                    default:
134 1
                        $textType = 'input';
135 1
                        break;
136
                }
137
            }
138
139
            return [
140 4
                'type' => $textType,
141 4
                'key' => $child->getName(),
142 4
                'templateOptions' => $templateOptions,
143
            ];
144
        }
145
    }
146
147 2
    protected function getAutocompleteUrl($dataclass)
148
    {
149 2
        $entityName = $dataclass;
150
151 2
        $routeName = 'autocomplete_' . strtolower($entityName);
152
153 2
        return $this->router->getRouteCollection()->get($routeName) ? $this->router->generate($routeName) : null;
154
    }
155
}
156