Issues (3099)

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.

src/Kunstmaan/FormBundle/Helper/FormHandler.php (2 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 Kunstmaan\FormBundle\Helper;
4
5
use ArrayObject;
6
use Doctrine\ORM\EntityManager;
7
use Kunstmaan\FormBundle\Entity\FormAdaptorInterface;
8
use Kunstmaan\FormBundle\Entity\FormSubmission;
9
use Kunstmaan\FormBundle\Entity\FormSubmissionField;
10
use Kunstmaan\FormBundle\Event\FormEvents;
11
use Kunstmaan\FormBundle\Event\SubmissionEvent;
12
use Kunstmaan\NodeBundle\Helper\RenderContext;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
15
use Symfony\Component\Form\Extension\Core\Type\FormType;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\Routing\RouterInterface;
20
21
/**
22
 * The form handler handles everything from creating the form to handling the submitted form
23
 */
24
class FormHandler implements FormHandlerInterface
25
{
26
    /**
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * @param ContainerInterface $container
33
     */
34
    public function __construct(ContainerInterface $container)
35
    {
36
        $this->container = $container;
37
    }
38
39
    /**
40
     * @param FormPageInterface $page    The form page
41
     * @param Request           $request The request
42
     * @param RenderContext     $context The render context
43
     *
44
     * @return RedirectResponse|void|null
45
     */
46
    public function handleForm(FormPageInterface $page, Request $request, RenderContext $context)
47
    {
48
        /* @var EntityManager $em */
49
        $em = $this->container->get('doctrine.orm.entity_manager');
50
        /* @var FormBuilderInterface $formBuilder */
51
        $formBuilder = $this->container->get('form.factory')->createBuilder(FormType::class);
52
        /* @var RouterInterface $router */
53
        $router = $this->container->get('router');
54
        /* @var ArrayObject $fields */
55
        $fields = new ArrayObject();
56
        $pageParts = $em->getRepository('KunstmaanPagePartBundle:PagePartRef')->getPageParts($page, $page->getFormElementsContext());
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Doctrine\Persistence\ObjectRepository as the method getPageParts() does only exist in the following implementations of said interface: Kunstmaan\PagePartBundle...y\PagePartRefRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
57
        foreach ($pageParts as $sequence => $pagePart) {
58
            if ($pagePart instanceof FormAdaptorInterface) {
59
                $pagePart->adaptForm($formBuilder, $fields, $sequence);
60
            }
61
        }
62
63
        $form = $formBuilder->getForm();
64
        if ($request->getMethod() == 'POST') {
65
            $form->handleRequest($request);
66
            if ($form->isSubmitted() && $form->isValid()) {
67
                $formSubmission = new FormSubmission();
68
                $formSubmission->setIpAddress($request->getClientIp());
69
                $formSubmission->setNode($em->getRepository('KunstmaanNodeBundle:Node')->getNodeFor($page));
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Doctrine\Persistence\ObjectRepository as the method getNodeFor() does only exist in the following implementations of said interface: Kunstmaan\NodeBundle\Repository\NodeRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
70
                $formSubmission->setLang($request->getLocale());
71
                $em->persist($formSubmission);
72
73
                /* @var FormSubmissionField $field */
74
                foreach ($fields as $field) {
75
                    $field->setSubmission($formSubmission);
76
                    $field->onValidPost($form, $formBuilder, $request, $this->container);
77
                    $em->persist($field);
78
                }
79
80
                $em->flush();
81
                $em->refresh($formSubmission);
82
83
                $event = new SubmissionEvent($formSubmission, $page);
84
                $this->dispatch($event, FormEvents::ADD_SUBMISSION);
85
86
                return new RedirectResponse($page->generateThankYouUrl($router, $context));
87
            }
88
        }
89
        $context['frontendform'] = $form->createView();
90
        $context['frontendformobject'] = $form;
91
92
        return null;
93
    }
94
95
    /**
96
     * @param object $event
97
     * @param string $eventName
98
     *
99
     * @return object
100
     */
101 View Code Duplication
    private function dispatch($event, string $eventName)
102
    {
103
        $eventDispatcher = $this->container->get('event_dispatcher');
104
        if (class_exists(LegacyEventDispatcherProxy::class)) {
105
            $eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
106
107
            return $eventDispatcher->dispatch($event, $eventName);
108
        }
109
110
        return $eventDispatcher->dispatch($eventName, $event);
111
    }
112
}
113