Issues (2)

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/CRUDlex/UserProvider.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
/*
4
 * This file is part of the CRUDlexUser package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[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 CRUDlex;
13
14
use Symfony\Component\Security\Core\User\UserProviderInterface;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
17
use CRUDlex\AbstractData;
18
use CRUDlex\User;
19
20
/**
21
 * The implementation of the UserProviderInterface to work with the CRUDlex API.
22
 */
23
class UserProvider implements UserProviderInterface
24
{
25
26
    /**
27
     * The Entity fieldname of the username.
28
     */
29
    protected $usernameField;
30
31
    /**
32
     * The fieldname of the password (hash).
33
     */
34
    protected $passwordField;
35
36
    /**
37
     * The fieldname of the password hash salt.
38
     */
39
    protected $saltField;
40
41
    /**
42
     * Holds the AbstractData instance to grab the user data from.
43
     */
44
    protected $userData;
45
46
    /**
47
     * Holds the AbstractData instance or the field of the many-to-many relationship to grab the user role data from.
48
     */
49
    protected $userRoleData;
50
51
    /**
52
     * Holds the AbstractData instance or the field of the many-to-many relationship to grab the user role data from.
53
     */
54
    protected $userRoleIdentifier;
55
56
    /**
57
     * Loads the roles of an user via an AbstractData instance.
58
     *
59
     * @param mixed $userId
60
     * the id of the user
61
     *
62
     * @return string[]
63
     * the roles of the user
64
     */
65
    protected function loadUserRolesViaData($userId)
66
    {
67
        $crudRoles = $this->userRoleIdentifier->listEntries(['user' => $userId], ['user' => '=']);
0 ignored issues
show
The method listEntries cannot be called on $this->userRoleIdentifier (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
68
        $roles = ['ROLE_USER'];
69
        if ($crudRoles !== null) {
70
            foreach ($crudRoles as $crudRole) {
71
                $role = $crudRole->get('role');
72
                $roles[] = $role['name'];
73
            }
74
        }
75
        return $roles;
76
    }
77
78
    /**
79
     * Loads the roles of an user via a many-to-many relationship
80
     *
81
     * @param Entity $user
82
     * the id of the user
83
     *
84
     * @return string[]
85
     * the roles of the user
86
     */
87
    protected function loadUserRolesViaManyToMany($user)
88
    {
89
        $roles = ['ROLE_USER'];
90
        if (is_string($this->userRoleIdentifier)) {
91
            foreach ($user->get($this->userRoleIdentifier) as $role) {
92
                $roles[] = $role['name'];
93
            }
94
        }
95
        return $roles;
96
    }
97
98
    /**
99
     * Constructor for data structures connecting users and roles via a many-to-many relationship on the user.
100
     *
101
     * @param Service $service
102
     * the Service instance to take the AbstractData of the users from
103
     *
104
     * @param string $userIdentifier
105
     * the identifier to of the user AbstractData
106
     *
107
     * @param string $userRoleIdentifier
108
     * the field of the many-to-many relationship to grab the user role data from or the AbstractData if its an own entity
109
     *
110
     * @param string $usernameField
111
     * the Entity fieldname of the username
112
     *
113
     * @param string $passwordField
114
     * the Entity fieldname of the password hash
115
     *
116
     * @param string $saltField
117
     * the Entity fieldname of the password hash salt
118
     */
119
    public function __construct(Service $service, $userIdentifier = 'user', $userRoleIdentifier = 'roles', $usernameField = 'username', $passwordField = 'password', $saltField = 'salt')
120
    {
121
        $this->userData = $service->getData($userIdentifier);
122
        $this->userRoleIdentifier = $userRoleIdentifier;
123
        $this->usernameField = $usernameField;
124
        $this->passwordField = $passwordField;
125
        $this->saltField = $saltField;
126
    }
127
128
    /**
129
     * Loads and returns an user by username.
130
     * Throws an UsernameNotFoundException on not existing username.
131
     *
132
     * @param string $username
133
     * the username
134
     *
135
     * @return User
136
     * the loaded user
137
     */
138
    public function loadUserByUsername($username)
139
    {
140
141
        $users = $this->userData->listEntries([$this->usernameField => $username], [$this->usernameField => '='], 0, 1);
142
        if (count($users) === 0) {
143
            throw new UsernameNotFoundException();
144
        }
145
146
        $user = $users[0];
147
        $roles = is_string($this->userRoleIdentifier) ? $this->loadUserRolesViaManyToMany($user) : $this->loadUserRolesViaData($user->get('id'));
148
149
        $userObj = new User($this->usernameField, $this->passwordField, $this->saltField, $user, $roles);
150
        return $userObj;
151
    }
152
153
    /**
154
     * Reloads and returns the given user.
155
     * Throws an UsernameNotFoundException if the user ceased to exist meanwhile.
156
     *
157
     * @param UserInterface $user
158
     * the user to reload
159
     *
160
     * @return User
161
     * the reloaded user
162
     */
163
    public function refreshUser(UserInterface $user)
164
    {
165
        $refreshedUser = $this->loadUserByUsername($user->getUsername());
166
        return $refreshedUser;
167
    }
168
169
    /**
170
     * Tests whether the given user class is supported by this UserProvider.
171
     *
172
     * @param string $class
173
     * the user class name to test
174
     *
175
     * @return boolean
176
     * true if the class is "CRUDlex\User"
177
     */
178
    public function supportsClass($class)
179
    {
180
        return $class === 'CRUDlex\User';
181
    }
182
183
}
184