Issues (78)

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/Drivers/AbstractAdapter.php (7 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 STS\StorageConnect\Drivers;
4
5
use Carbon\Carbon;
6
use Illuminate\Http\RedirectResponse;
7
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
8
use STS\StorageConnect\Events\CloudStorageSetup;
9
use STS\StorageConnect\Models\CloudStorage;
10
use STS\StorageConnect\Models\CustomManagedCloudStorage;
11
use STS\StorageConnect\Models\Quota;
12
use STS\StorageConnect\UploadRequest;
13
use STS\StorageConnect\UploadResponse;
14
15
abstract class AbstractAdapter
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $driver;
21
22
    /**
23
     * @var string
24
     */
25
    protected $providerClass;
26
27
    /**
28
     * @var array
29
     */
30
    protected $config;
31
32
    /**
33
     * @var AbstractProvider
34
     */
35
    protected $provider;
36
37
    /**
38
     * @var mixed
39
     */
40
    protected $service;
41
42
    /**
43
     * @var array
44
     */
45
    protected $token;
46
47
    /**
48
     * @var callable
49
     */
50
    protected $tokenUpdateCallback;
51
52
    /**
53
     * DropboxAdapter constructor.
54
     *
55
     * @param array $config
56
     */
57
    public function __construct(array $config)
58
    {
59
        $this->config = $config;
60
    }
61
62
    /**
63
     * @param $token
64
     * @param null $callback
65
     *
66
     * @return $this
67
     * @paran $callback
68
     *
69
     */
70
    public function setToken($token, $callback = null)
71
    {
72
        $this->token = $token;
73
        $this->tokenUpdateCallback = $callback;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param $token
80
     */
81
    protected function updateToken($token)
82
    {
83
        if ($this->tokenUpdateCallback) {
84
            call_user_func($this->tokenUpdateCallback, $token);
85
        }
86
    }
87
88
    /**
89
     * @param CloudStorage $storage
90
     * @param null $redirectUrl
91
     *
92
     * @return RedirectResponse
93
     */
94
    public function authorize(CloudStorage $storage, $redirectUrl = null)
95
    {
96
        if (!$storage->exists) {
97
            $storage->save();
98
        }
99
100
        if ($storage instanceof CustomManagedCloudStorage) {
101
            $this->provider()->session()->put('storage-connect.custom', true);
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SocialiteProviders\Manager\OAuth2\AbstractProvider as the method session() does only exist in the following sub-classes of SocialiteProviders\Manager\OAuth2\AbstractProvider: STS\StorageConnect\Drivers\Dropbox\Provider, STS\StorageConnect\Drivers\Google\Provider. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
102
        } else {
103
            $this->provider()->session()->put('storage-connect.id', $storage->id);
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SocialiteProviders\Manager\OAuth2\AbstractProvider as the method session() does only exist in the following sub-classes of SocialiteProviders\Manager\OAuth2\AbstractProvider: STS\StorageConnect\Drivers\Dropbox\Provider, STS\StorageConnect\Drivers\Google\Provider. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
104
        }
105
106
        if ($redirectUrl != null) {
107
            $this->provider()->session()->put('storage-connect.redirect', $redirectUrl);
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SocialiteProviders\Manager\OAuth2\AbstractProvider as the method session() does only exist in the following sub-classes of SocialiteProviders\Manager\OAuth2\AbstractProvider: STS\StorageConnect\Drivers\Dropbox\Provider, STS\StorageConnect\Drivers\Google\Provider. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
108
        }
109
110
        return $this->provider()->redirect();
111
    }
112
113
    /**
114
     * @param CloudStorage $storage
115
     *
116
     * @return void
117
     */
118
    public function finish(CloudStorage $storage)
119
    {
120
        $this->setToken($this->provider()->user()->accessTokenResponseBody);
121
122
        $storage->update(array_merge(
123
            [
124
                'token'     => $this->provider()->user()->accessTokenResponseBody,
125
                'connected' => 1,
126
                'enabled'   => 1,
127
                'enabled_at' => Carbon::now()
128
            ],
129
            $this->mapUserDetails($this->provider()->user())
130
        ));
131
        $storage->updateQuota($this->getQuota());
132
133
        event(new CloudStorageSetup($storage));
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function driver()
140
    {
141
        return $this->driver;
142
    }
143
144
    /**
145
     * @return AbstractProvider
146
     */
147
    public function provider()
148
    {
149
        if (!$this->provider) {
150
            $this->setProvider($this->makeProvider());
151
        }
152
153
        return $this->provider;
154
    }
155
156
    public function setProvider(AbstractProvider $provider)
157
    {
158
        $this->provider = $provider;
159
    }
160
161
    /**
162
     * @return mixed
163
     */
164
    public function service()
165
    {
166
        if (!$this->service) {
167
            $this->setService($this->makeService());
168
        }
169
170
        return $this->service;
171
    }
172
173
    /**
174
     * @param $service
175
     *
176
     * @return AbstractAdapter
177
     */
178
    public function setService($service)
179
    {
180
        $this->service = $service;
181
182
        return $this;
183
    }
184
185
    /**
186
     * @return AbstractProvider
187
     */
188
    protected function makeProvider() {
189
        return app($this->providerClass);
190
    }
191
192
    /**
193
     * @return mixed
194
     */
195
    abstract protected function makeService();
196
197
    /**
198
     * @return Quota
199
     */
200
    abstract function getQuota();
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
201
202
    /**
203
     * @param $user
204
     *
205
     * @return array
206
     */
207
    abstract protected function mapUserDetails($user);
208
209
    /**
210
     * @param UploadRequest $request
211
     *
212
     * @return UploadResponse
213
     */
214
    abstract function upload(UploadRequest $request);
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
215
216
    /**
217
     * @param UploadResponse $response
218
     *
219
     * @return UploadResponse
220
     */
221
    abstract function checkUploadStatus(UploadResponse $response);
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
222
223
    /**
224
     * @param string $remotePath
225
     *
226
     * @return bool
227
     */
228
    abstract function pathExists($remotePath);
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
229
}