This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 App\Helpers; |
||
4 | |||
5 | use App\Facades\Session; |
||
0 ignored issues
–
show
|
|||
6 | use App\Models\ChocolateyId; |
||
7 | use App\Models\User as UserModel; |
||
8 | use App\Singleton; |
||
9 | use Illuminate\Http\Request; |
||
10 | use Illuminate\Support\Facades\Config; |
||
11 | |||
12 | /** |
||
13 | * Class User. |
||
14 | */ |
||
15 | final class User extends Singleton |
||
16 | { |
||
17 | /** |
||
18 | * Update User Data without overwriting Session. |
||
19 | * |
||
20 | * @param array $parameters |
||
21 | * |
||
22 | * @return UserModel |
||
23 | */ |
||
24 | public function updateSession(array $parameters) |
||
25 | { |
||
26 | return $this->setSession($this->updateUser($this->getUser(), $parameters)); |
||
0 ignored issues
–
show
It seems like
$this->getUser() can be null ; however, updateUser() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
![]() |
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Set User Data on Session. |
||
31 | * |
||
32 | * @param UserModel $user |
||
33 | * |
||
34 | * @return UserModel |
||
35 | */ |
||
36 | public function setSession(UserModel $user) |
||
37 | { |
||
38 | return Session::set(Config::get('chocolatey.security.session'), $user); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Update User Data by User Model. |
||
43 | * |
||
44 | * @param UserModel $user |
||
45 | * @param array $parameters |
||
46 | * |
||
47 | * @return UserModel |
||
48 | */ |
||
49 | public function updateUser($user, array $parameters) |
||
50 | { |
||
51 | $user->update($parameters); |
||
52 | |||
53 | return $user; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get User Data from Session |
||
58 | * If User Session doesn't exists, return null. |
||
59 | * |
||
60 | * @return UserModel|null |
||
61 | */ |
||
62 | public function getUser() |
||
63 | { |
||
64 | return Session::get(Config::get('chocolatey.security.session')) ?? null; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Retrieve Non Banned Users (If all Users are Banned, return the Banned user Also). |
||
69 | * |
||
70 | * @param Request $request |
||
71 | * @param ChocolateyId $chocolateyId |
||
72 | * |
||
73 | * @return UserModel |
||
74 | */ |
||
75 | private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) |
||
0 ignored issues
–
show
|
|||
76 | { |
||
77 | $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
||
78 | |||
79 | foreach ($temporaryUsers as $forUser) { |
||
80 | if (!$forUser->isBanned) { |
||
81 | return $forUser; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return $temporaryUsers->get(0); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Get Users. |
||
90 | * |
||
91 | * @param Request $request |
||
92 | * @param ChocolateyId $chocolateyId |
||
93 | * |
||
94 | * @return UserModel |
||
95 | */ |
||
96 | private function retrieveUser(Request $request, ChocolateyId $chocolateyId) |
||
97 | { |
||
98 | if ($chocolateyId->last_logged_id != 0) { |
||
99 | $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
||
100 | |||
101 | if ($temporaryUser->isBanned) { |
||
102 | return $this->checkForBanAlternative($request, $chocolateyId); |
||
103 | } |
||
104 | |||
105 | return $temporaryUser; |
||
106 | } |
||
107 | |||
108 | $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
||
109 | |||
110 | if ($temporaryUser->isBanned) { |
||
111 | return $this->checkForBanAlternative($request, $chocolateyId); |
||
112 | } |
||
113 | |||
114 | return $temporaryUser; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Set Session From Login Credentials. |
||
119 | * |
||
120 | * @param Request $request |
||
121 | * |
||
122 | * @return UserModel |
||
123 | */ |
||
124 | public function loginUser(Request $request) |
||
125 | { |
||
126 | $chocolateyId = ChocolateyId::find($request->json()->get('email')); |
||
127 | |||
128 | if ($chocolateyId == null) { |
||
129 | return; |
||
130 | } |
||
131 | |||
132 | $user = $this->retrieveUser($request, $chocolateyId); |
||
133 | |||
134 | $chocolateyId->last_logged_id = $user->uniqueId; |
||
135 | |||
136 | return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password')) |
||
137 | ? $this->setSession($user) : null; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Return if USer Session Exists. |
||
142 | * |
||
143 | * @return bool |
||
144 | */ |
||
145 | public function hasSession() |
||
146 | { |
||
147 | return (bool) Session::get(Config::get('chocolatey.security.session')); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Erase User Session. |
||
152 | */ |
||
153 | public function eraseSession() |
||
154 | { |
||
155 | Session::erase(Config::get('chocolatey.security.session')); |
||
156 | } |
||
157 | } |
||
158 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: