Issues (29)

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/Controller/RegistrationController.php (2 issues)

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
/*
4
 * This file is part of the awurth/silex-user package.
5
 *
6
 * (c) Alexis Wurth <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AWurth\Silex\User\Controller;
13
14
use AWurth\Silex\User\Event\Events;
15
use AWurth\Silex\User\Event\FilterUserResponseEvent;
16
use AWurth\Silex\User\Event\FormEvent;
17
use AWurth\Silex\User\Event\GetResponseUserEvent;
18
use AWurth\Silex\User\Form\Type\RegistrationFormType;
19
use AWurth\Silex\User\Model\UserInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
23
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
24
25
/**
26
 * User Registration Controller.
27
 *
28
 * @author Alexis Wurth <[email protected]>
29
 */
30
class RegistrationController extends Controller
31
{
32
    public function registerAction(Request $request)
33
    {
34
        $userManager = $this->getUserManager();
35
        $dispatcher = $this->getDispatcher();
36
37
        $user = $userManager->createUser();
38
        $user->setEnabled(true);
39
40
        $event = new GetResponseUserEvent($user, $request);
41
        $dispatcher->dispatch(Events::REGISTRATION_INITIALIZE, $event);
42
43
        if (null !== $event->getResponse()) {
44
            return $event->getResponse();
45
        }
46
47
        $form = $this->createForm(RegistrationFormType::class, $user);
48
49
        $form->handleRequest($request);
50
51
        if ($form->isSubmitted()) {
52
            if ($form->isValid()) {
53
                $event = new FormEvent($form, $request);
54
                $dispatcher->dispatch(Events::REGISTRATION_SUCCESS, $event);
55
56
                $userManager->updateUser($user);
57
58
                $response = $event->getResponse();
0 ignored issues
show
Are you sure the assignment to $response is correct as $event->getResponse() (which targets AWurth\Silex\User\Event\FormEvent::getResponse()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
59
                if (null === $response) {
60
                    $response = $this->redirect('silex_user.registration_confirmed');
61
                }
62
63
                $dispatcher->dispatch(Events::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
64
65
                return $response;
66
            }
67
68
            $event = new FormEvent($form, $request);
69
            $dispatcher->dispatch(Events::REGISTRATION_FAILURE, $event);
70
71
            $response = $event->getResponse();
0 ignored issues
show
Are you sure the assignment to $response is correct as $event->getResponse() (which targets AWurth\Silex\User\Event\FormEvent::getResponse()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
72
            if (null !== $response) {
73
                return $response;
74
            }
75
        }
76
77
        return $this->render('silex_user/registration/register.twig', [
78
            'form' => $form->createView()
79
        ]);
80
    }
81
82
    /**
83
     * Tell the user to check their email provider.
84
     */
85
    public function checkEmailAction()
86
    {
87
        $session = $this->getSession();
88
        $email = $session->get('silex_user_confirmation_email');
89
90
        if (empty($email)) {
91
            return $this->redirect('silex_user.register');
92
        }
93
94
        $session->remove('silex_user_confirmation_email');
95
        $user = $this->getUserManager()->findUserByEmail($email);
96
97
        if (null === $user) {
98
            throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email));
99
        }
100
        
101
        return $this->render('silex_user/registration/check_email.twig', [
102
            'user' => $user
103
        ]);
104
    }
105
106
    /**
107
     * Receive the confirmation token from user email provider and login the user.
108
     *
109
     * @param Request $request
110
     * @param string $token
111
     *
112
     * @return Response
113
     */
114
    public function confirmAction(Request $request, $token)
115
    {
116
        $userManager = $this->getUserManager();
117
118
        $user = $userManager->findUserByConfirmationToken($token);
119
120
        if (null === $user) {
121
            throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
122
        }
123
124
        $dispatcher = $this->getDispatcher();
125
126
        $user->setConfirmationToken(null);
127
        $user->setEnabled(true);
128
129
        $event = new GetResponseUserEvent($user, $request);
130
        $dispatcher->dispatch(Events::REGISTRATION_CONFIRM, $event);
131
132
        $userManager->updateUser($user);
133
134
        $response = $event->getResponse();
135
        if (null === $response) {
136
            $response = $this->redirect('silex_user.registration_confirmed');
137
        }
138
        
139
        $dispatcher->dispatch(Events::REGISTRATION_CONFIRMED, new FilterUserResponseEvent($user, $request, $response));
140
141
        return $response;
142
    }
143
144
    /**
145
     * Tell the user their account is confirmed.
146
     */
147
    public function confirmedAction()
148
    {
149
        $user = $this->getUser();
150
        if (!is_object($user) || !$user instanceof UserInterface) {
151
            throw new AccessDeniedException('This user does not have access to this section.');
152
        }
153
154
        return $this->render('silex_user/registration/confirmed.twig', [
155
            'user' => $user
156
        ]);
157
    }
158
}
159