Issues (415)

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.

app/Services/SocialiteUser.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 App\Services;
4
5
use App\Repositories\UserRepository;
6
use App\Socialite;
7
use Auth;
8
use Laravel\Socialite\Contracts\User as ProviderUser;
9
use App\Repositories\SocialiteRepository;
10
11
class SocialiteUser
12
{
13
    /**
14
     * @var ProviderUser
15
     */
16
    private $user;
17
18
    /**
19
     * @var string
20
     */
21
    private $provider;
22
23
    /**
24
     * SocialiteUser constructor.
25
     */
26
    public function __construct()
27
    {
28
        $this->socialRepository = $this->getSocialiteRepository();
0 ignored issues
show
The property socialRepository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
    }
30
31
    /**
32
     * @param $provider
33
     * @param $callback
34
     * @return $this
35
     */
36
    public function init($provider, $callback)
37
    {
38
        $this
39
            ->setProvider($provider)
40
            ->setUser($callback);
41
42
        return $this;
43
    }
44
45
    /**
46
     * Register.
47
     *
48
     * @return mixed|null
49
     */
50
    public function register()
51
    {
52
        if ($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId()))
53
        {
54
            $s_user = $this->socialRepository->getUserByProvider(
55
                $this->getProvider(), $this->user()->getId()
56
            );
57
58
            if($user = $s_user->user)
59
                return $user;
60
61
            return $this;
62
        }
63
64
        $social = $this->getOrCreateEmptySocialUser();
65
66
        if($this->checkEmail())
67
            return $this->createSocialUserWithEmail($social);
0 ignored issues
show
$social is of type null|object<App\Services\SocialiteUser>, but the function expects a object<App\Socialite>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return mixed
74
     */
75
    public function getProvider()
76
    {
77
        return $this->provider;
78
    }
79
80
    /**
81
     * @return ProviderUser
82
     */
83
    public function getUser()
84
    {
85
        return $this->user;
86
    }
87
88
    /**
89
     * Set user.
90
     *
91
     * @param $user
92
     * @return $this
93
     */
94
    public function setUser($user)
95
    {
96
        $this->user = $user;
97
98
        return $this;
99
    }
100
101
    /**
102
     * Set provider.
103
     *
104
     * @param $provider
105
     * @return $this
106
     */
107
    public function setProvider($provider)
108
    {
109
        $this->provider = $provider;
110
111
        return $this;
112
    }
113
114
    /**
115
     * @return ProviderUser
116
     */
117
    protected function user()
118
    {
119
        return $this->getUser();
120
    }
121
122
    /**
123
     * Get or create social user
124
     *
125
     * @return null|static
126
     */
127
    protected function getOrCreateEmptySocialUser()
128
    {
129
        if($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId()))
130
            return $this->socialRepository->getUserByProvider($this->getProvider(), $this->user()->getId());
131
132
        return $this->socialRepository->createEmpty(
133
            $this->getProvider(), $this->user()
134
        );
135
    }
136
137
    /**
138
     * @return SocialiteRepository
139
     */
140
    private function getSocialiteRepository()
141
    {
142
        return new SocialiteRepository();
143
    }
144
145
    /**
146
     * @return UserRepository
147
     */
148
    private function getUserRepository()
149
    {
150
        return new UserRepository();
151
    }
152
153
    /**
154
     * Associate user.
155
     *
156
     * @param $account
157
     * @param null $email
158
     * @return mixed
159
     */
160
    private function associateSocialiteUser($account, $email = null)
161
    {
162
        if(! $email)
163
            $email = $this->user()->getEmail();
164
165
        $user = $this->getUserRepository()->getByEmail($email);
166
        $account->user()->associate($user);
167
        $account->save();
168
169
        return $user;
170
    }
171
172
    /**
173
     * Check if email exists;
174
     *
175
     * @return bool
176
     */
177
    private function checkEmail()
178
    {
179
        return (bool) $this->user()->getEmail();
180
    }
181
182
    /**
183
     * @param $social
184
     * @return bool
185
     */
186
    public function tryToAssociateUser($social, $email = null)
187
    {
188
        if(! $email)
189
            $email = $this->user()->getEmail();
190
191
        if($this->getUserRepository()->checkIfUserExists($email))
192
            return $this->associateSocialiteUser($social, $email);
193
194
        return false;
195
    }
196
197
    /**
198
     * Create social user.
199
     *
200
     * @param Socialite $social
201
     * @return mixed
202
     */
203
    private function createSocialUserWithEmail(Socialite $social)
204
    {
205
        $this->tryToAssociateUser($social);
206
        $names = $this->getFirstAndLustNames();
207
208
        return $this->getUserRepository()->create([
0 ignored issues
show
The method create() does not exist on App\Repositories\UserRepository. Did you maybe mean createSimpleUser()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
209
            'email' => $this->user()->getEmail(),
210
            'name' => $this->user()->getName(),
211
            'password' => $this->users->hashPassword(str_random(45)),
0 ignored issues
show
The property users does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
212
            'firstname' => @$names[0],
213
            'lastname' => @$names[1]
214
        ]);
215
    }
216
217
    /**
218
     * @param null $name
219
     * @return array
220
     */
221
    public function getFirstAndLustNames($name = null)
222
    {
223
        if(! $name)
224
            $name = $this->user()->getName();
225
226
        return explode(' ', $name);
227
    }
228
229
    /**
230
     * Login the user.
231
     *
232
     * @param $user
233
     */
234
    public function login($user)
235
    {
236
        \Auth::login($user, true);
237
    }
238
239
    /**
240
     * Add avatar.
241
     *
242
     * @param $avatar
243
     * @return $this
244
     */
245
    public function avatar($avatar)
246
    {
247
        (new ImageProcessor())->changeAvatar($avatar);
248
249
        return $this;
250
    }
251
}