Issues (184)

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/AppBundle/Security/FormAuthenticator.php (1 issue)

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
namespace AppBundle\Security;
3
4
use AppBundle\Form\Type\LoginFormType;
5
use AppBundle\Service\UserService;
6
use Symfony\Component\Form\FormFactoryInterface;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\RouterInterface;
11
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
12
use Symfony\Component\Security\Core\Exception\AuthenticationException;
13
use Symfony\Component\Security\Core\Security;
14
use Symfony\Component\Security\Core\User\UserInterface;
15
use Symfony\Component\Security\Core\User\UserProviderInterface;
16
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
17
18
class FormAuthenticator extends AbstractGuardAuthenticator
19
{
20
    /** @var FormFactoryInterface */
21
    private $formFactory;
22
23
    /** @var RouterInterface */
24
    private $router;
25
26
    /** @var UserService */
27
    private $userService;
28
29
    public function __construct(FormFactoryInterface $formFactory, RouterInterface $router, UserService $userService)
30
    {
31
        $this->formFactory = $formFactory;
32
        $this->router = $router;
33
        $this->userService = $userService;
34
    }
35
36
    //region GuardAuthenticatorInterface
37
38
    //region AuthenticationEntryPointInterface
39
40
    /**
41
     * @inheritdoc
42
     *
43
     * @param Request $request The request that resulted in an AuthenticationException
44
     * @param AuthenticationException $authException The exception that started the authentication process
45
     *
46
     * @return Response
47
     */
48
    public function start(Request $request, AuthenticationException $authException = null)
49
    {
50
        return new RedirectResponse($this->getLoginPath());
51
    }
52
53
    //endregion
54
55
    /**
56
     * @inheritdoc
57
     *
58
     * @param Request $request
59
     *
60
     * @return UserCredentials|null
61
     */
62
    public function getCredentials(Request $request)
63
    {
64
        if (!$request->isMethod('POST')) {
65
            return null;
66
        }
67
68
        if ($request->getPathInfo() !== $this->getLoginPath()) {
69
            return null;
70
        }
71
72
        $form = $this->formFactory->create(LoginFormType::class, null, []);
73
        $form->handleRequest($request);
74
75
        $username = $form->get('username')->getData();
76
        $this->setLastAuthenticationUsername($request, $username);
77
78
        $credentials = new UserCredentials(
79
            $username,
80
            $form->get('password')->getData(),
81
            $form->get('type')->getData()
82
        );
83
84
        return $credentials;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     *
90
     * @param UserCredentials $credentials
91
     * @param UserProviderInterface $userProvider
92
     *
93
     * @throws AuthenticationException
94
     *
95
     * @return UserInterface|null
96
     */
97
    public function getUser($credentials, UserProviderInterface $userProvider)
98
    {
99
        return $userProvider->loadUserByUsername($credentials->getUsernameCompound());
100
    }
101
102
    /**
103
     * @inheritdoc
104
     *
105
     * @param UserCredentials $credentials
106
     * @param UserInterface $user
107
     *
108
     * @return bool
109
     */
110
    public function checkCredentials($credentials, UserInterface $user)
111
    {
112
        return $this->userService->validatePassword($user, $credentials->getPassword());
0 ignored issues
show
$user of type object<Symfony\Component...ore\User\UserInterface> is not a sub-type of object<AppBundle\Entity\User>. It seems like you assume a concrete implementation of the interface Symfony\Component\Security\Core\User\UserInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
113
    }
114
115
    /**
116
     * Called when authentication executed, but failed (e.g. wrong username password).
117
     *
118
     * @inheritdoc
119
     *
120
     * @param Request $request
121
     * @param AuthenticationException $exception
122
     *
123
     * @return Response|null
124
     */
125
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
126
    {
127
        $this->setLastAuthenticationError($request, $exception);
128
129
        return new RedirectResponse($this->getLoginPath());
130
    }
131
132
    /**
133
     * Called when authentication executed and was successful!
134
     *
135
     * @inheritdoc
136
     *
137
     * @param Request $request
138
     * @param TokenInterface $token
139
     * @param string $providerKey The provider (i.e. firewall) key
140
     *
141
     * @return Response|null
142
     */
143
    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
144
    {
145
        $targetPath = $this->getTargetPath($request, $providerKey);
146
147
        if (empty($targetPath)) {
148
            $targetPath = $this->getHomepagePath();
149
        }
150
151
        return new RedirectResponse($targetPath);
152
    }
153
154
    /**
155
     * Authenticator supports "remember me" functionality
156
     *
157
     * @return bool
158
     */
159
    public function supportsRememberMe()
160
    {
161
        return true;
162
    }
163
164
    //endregion
165
166
    //region Page URLs
167
168
    /**
169
     * Homepage URI
170
     *
171
     * @return string
172
     */
173
    private function getHomepagePath()
174
    {
175
        return $this->router->generate('homepage');
176
    }
177
178
    /**
179
     * Login page URI
180
     *
181
     * @return string
182
     */
183
    private function getLoginPath()
184
    {
185
        return $this->router->generate('login');
186
    }
187
188
    //endregion
189
190
    //region Authentication utils
191
192
    private function getTargetPath(Request $request, $providerKey)
193
    {
194
        return $request->getSession()->get('_security.'.$providerKey.'.target_path');
195
    }
196
197
    private function setLastAuthenticationError(Request $request, AuthenticationException $exception)
198
    {
199
        $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
200
    }
201
202
    private function setLastAuthenticationUsername(Request $request, $username)
203
    {
204
        $request->getSession()->set(Security::LAST_USERNAME, $username);
205
    }
206
207
    //endregion
208
}
209