Issues (40)

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.

Entity/BaseUser.php (4 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 SumoCoders\FrameworkMultiUserBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Serializable;
9
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Interfaces\UserDataTransferObject;
10
use SumoCoders\FrameworkMultiUserBundle\Security\PasswordResetToken;
11
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User;
12
use SumoCoders\FrameworkMultiUserBundle\ValueObject\Status;
13
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
14
use Symfony\Component\Security\Core\User\EquatableInterface;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
17
/**
18
 * @ORM\Entity(repositoryClass="SumoCoders\FrameworkMultiUserBundle\User\DoctrineBaseUserRepository")
19
 * @ORM\InheritanceType("JOINED")
20
 * @ORM\DiscriminatorColumn(name="discr", type="string")
21
 */
22
class BaseUser implements User, Serializable, EquatableInterface
23
{
24
    /**
25
     * @var int
26
     *
27
     * @ORM\Column(type="integer")
28
     * @ORM\Id
29
     * @ORM\GeneratedValue
30
     */
31
    protected $id;
32
33
    /**
34
     * @var string
35
     *
36
     * @ORM\Column(type="string")
37
     */
38
    protected $username;
39
40
    /**
41
     * @var string
42
     *
43
     * @ORM\Column(type="string")
44
     */
45
    protected $password;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(type="string")
51
     */
52
    protected $salt;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(type="string")
58
     */
59
    protected $displayName;
60
61
    /**
62
     * @var PasswordResetToken
63
     *
64
     * @ORM\Column(type="string", nullable=true)
65
     */
66
    protected $passwordResetToken;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(type="string")
72
     */
73
    protected $email;
74
75
    /**
76
     * @var Status
77
     *
78
     * @ORM\Column(type="user_status")
79
     */
80
    protected $status;
81
82
    /**
83
     * @var string
84
     */
85
    protected $plainPassword;
86
87
    /**
88
     * @var Collection
89
     *
90
     * @ORM\ManyToMany(targetEntity="SumoCoders\FrameworkMultiUserBundle\Entity\UserRole")
91
     */
92
    protected $roles;
93
94
    /**
95
     * @param string $username
96
     * @param string $plainPassword
97
     * @param string $displayName
98
     * @param string $email
99
     * @param Collection $roles
100
     * @param int $id
101
     * @param PasswordResetToken $token
102
     */
103
    public function __construct(
104
        string $username,
105
        string $plainPassword,
106
        string $displayName,
107
        string $email,
108
        Collection $roles,
109
        int $id = null,
110
        PasswordResetToken $token = null
111
    ) {
112
        $this->username = $username;
113
        $this->plainPassword = $plainPassword;
114
        $this->displayName = $displayName;
115
        $this->email = $email;
116
        $this->roles = $roles;
117
        $this->id = $id;
118
119
        // set the default status to active
120
        $this->status = Status::active();
0 ignored issues
show
Documentation Bug introduced by
It seems like \SumoCoders\FrameworkMul...Object\Status::active() of type object<self> is incompatible with the declared type object<SumoCoders\Framew...dle\ValueObject\Status> of property $status.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
121
122
        if ($token) {
123
            $this->passwordResetToken = $token;
124
        }
125
    }
126
127
    public function getRoles(): ?array
128
    {
129
        return $this->roles->toArray();
130
    }
131
132
    public function getRolesAsCollection(): ?Collection
133
    {
134
        return $this->roles;
135
    }
136
137
    public function getPassword(): string
138
    {
139
        return $this->password;
140
    }
141
142
    public function getSalt(): string
143
    {
144
        return $this->salt;
145
    }
146
147
    public function encodePassword(PasswordEncoderInterface $encoder): void
148
    {
149
        if (empty($this->plainPassword)) {
150
            return;
151
        }
152
153
        if (empty($this->salt)) {
154
            $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
155
        }
156
157
        $this->password = $encoder->encodePassword($this->plainPassword, $this->salt);
158
        $this->eraseCredentials();
159
    }
160
161
    public function getUsername(): string
162
    {
163
        return $this->username;
164
    }
165
166
    public function eraseCredentials(): void
167
    {
168
        $this->plainPassword = null;
169
    }
170
171
    public function getDisplayName(): string
172
    {
173
        return $this->displayName;
174
    }
175
176
    public function __toString(): string
177
    {
178
        return $this->getDisplayName();
179
    }
180
181
    public function clearPasswordResetToken(): self
182
    {
183
        $this->passwordResetToken = null;
184
185
        return $this;
186
    }
187
188
    public function generatePasswordResetToken(): self
189
    {
190
        $this->passwordResetToken = PasswordResetToken::generate();
191
192
        return $this;
193
    }
194
195
    public function getPasswordResetToken(): ?PasswordResetToken
196
    {
197
        return $this->passwordResetToken;
198
    }
199
200
    public function getEmail(): string
201
    {
202
        return $this->email;
203
    }
204
205
    public function setPassword(string $password): self
206
    {
207
        $this->plainPassword = $password;
208
209
        return $this;
210
    }
211
212
    public function getId(): int
213
    {
214
        return $this->id;
215
    }
216
217
    public function hasPlainPassword(): bool
218
    {
219
        return !empty($this->plainPassword);
220
    }
221
222
    public function getPlainPassword(): string
223
    {
224
        return $this->plainPassword;
225
    }
226
227
    public function change(UserDataTransferObject $data): void
228
    {
229
        $this->username = $data->getUserName();
230
        $this->plainPassword = $data->getPlainPassword();
231
        $this->displayName = $data->getDisplayName();
232
        $this->email = $data->getEmail();
233
    }
234
235
    public function toggleBlock(): void
236
    {
237
        if ((string) $this->status === Status::BLOCKED) {
238
            $this->status = Status::active();
0 ignored issues
show
Documentation Bug introduced by
It seems like \SumoCoders\FrameworkMul...Object\Status::active() of type object<self> is incompatible with the declared type object<SumoCoders\Framew...dle\ValueObject\Status> of property $status.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
239
240
            return;
241
        }
242
243
        $this->status = Status::blocked();
0 ignored issues
show
Documentation Bug introduced by
It seems like \SumoCoders\FrameworkMul...bject\Status::blocked() of type object<self> is incompatible with the declared type object<SumoCoders\Framew...dle\ValueObject\Status> of property $status.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
244
    }
245
246
    public function isBlocked(): bool
247
    {
248
        return $this->status->isBlocked();
249
    }
250
251
    public function canSwitchTo(BaseUser $user): bool
0 ignored issues
show
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
252
    {
253
        return false;
254
    }
255
256
    public function serialize(): string
257
    {
258
        return serialize(
259
            [
260
                $this->id,
261
                $this->username,
262
            ]
263
        );
264
    }
265
266
    public function unserialize($serialized): void
267
    {
268
        [$this->id, $this->username] = unserialize($serialized);
269
    }
270
271
    public function isEqualTo(UserInterface $user): bool
272
    {
273
        if ($user instanceof self) {
274
            return $user->getId() === $this->getId();
275
        }
276
277
        return false;
278
    }
279
}
280