Issues (5)

Security Analysis    no request data  

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/Easemob/Easemob.php (1 issue)

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 light/easemob.
5
 *
6
 * (c) lichunqiang <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace light\Easemob;
13
14
use Doctrine\Common\Cache\Cache;
15
use Doctrine\Common\Cache\FilesystemCache;
16
use light\Easemob\Core\AccessToken;
17
use light\Easemob\Core\Config;
18
use light\Easemob\Core\Http;
19
use light\Easemob\Providers\ChatProvider;
20
use light\Easemob\Providers\ChatRoomProvider;
21
use light\Easemob\Providers\FileProvider;
22
use light\Easemob\Providers\GroupProvider;
23
use light\Easemob\Providers\MessageProvider;
24
use light\Easemob\Providers\UserProvider;
25
use light\Easemob\Support\Log;
26
use Monolog\Handler\NullHandler;
27
use Monolog\Handler\StreamHandler;
28
use Monolog\Logger;
29
use Pimple\Container;
30
use Pimple\ServiceProviderInterface;
31
32
/**
33
 * Class Easemob.
34
 *
35
 * @property \light\Easemob\Rest\User user
36
 * @property \light\Easemob\Rest\Message message
37
 * @property \light\Easemob\Rest\File file
38
 * @property \light\Easemob\Rest\Chat chat
39
 * @property \light\Easemob\Rest\ChatRoom chatroom
40
 * @property \light\Easemob\Rest\Group group
41
 */
42
class Easemob extends Container
43
{
44
    const BASE_URL = 'https://a1.easemob.com';
45
46
    /**
47
     * Core service providers.
48
     *
49
     * @var array
50
     */
51
    protected $coreProviders = [
52
        UserProvider::class,
53
        ChatProvider::class,
54
        ChatRoomProvider::class,
55
        FileProvider::class,
56
        GroupProvider::class,
57
        MessageProvider::class,
58
    ];
59
60
    /**
61
     * @var string
62
     */
63
    protected $api;
64
65 12
    public function __construct(array $config)
66
    {
67 12
        parent::__construct();
68
69
        $this['config'] = function () use ($config) {
70 12
            return new Config($config);
71
        };
72
73
        //init api url
74 12
        $this->api = self::BASE_URL . '/' . $this['config']['enterpriseId'] . '/' . $this['config']['appId'] . '/';
75
76 12
        $this->registerCoreProviders();
0 ignored issues
show
The call to the method light\Easemob\Easemob::registerCoreProviders() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
77 12
        $this->registerProviders();
78 12
        $this->initializeLogger();
79
80 12
        Log::debug('Configuration:', ['config' => $this['config']]);
81 12
    }
82
83
    /**
84
     * Get all providers.
85
     *
86
     * @return array
87
     */
88
    public function getProviders()
89
    {
90
        return $this->coreProviders;
91
    }
92
93
    /**
94
     * @param ServiceProviderInterface $provider
95
     *
96
     * @return $this
97
     */
98 3
    public function setProvider(ServiceProviderInterface $provider)
99
    {
100
        $this->coreProviders[] = $provider;
101
102 3
        return $this;
103
    }
104
105
    /**
106
     * @param array $providers
107
     */
108
    public function setProviders(array $providers)
109
    {
110
        $this->coreProviders = [];
111
112
        foreach ($providers as $provider) {
113
            $this->setProvider($provider);
114
        }
115
    }
116
117
    /**
118
     * Register providers.
119
     */
120 12
    protected function registerProviders()
121
    {
122 12
        foreach ($this->coreProviders as $provider) {
123 12
            $this->register(new $provider());
124 12
        }
125 12
    }
126
127
    /**
128
     * Register core providers.
129
     */
130 12
    protected function registerCoreProviders()
131
    {
132
        $this['http'] = function () {
133 3
            return new Http($this->api);
134
        };
135
136
        $this['cache'] = function () {
137 3
            return new FilesystemCache($this['config']['cachePath'] ?: sys_get_temp_dir());
138
        };
139
140 3
        $this['access_token'] = function () {
141 3
            return new AccessToken(
142 3
                $this['config']['clientId'],
143 3
                $this['config']['clientSecret'],
144 3
                $this['http'],
145 3
                $this['cache']
146 3
            );
147
        };
148 12
    }
149
150
    /**
151
     * Init logger.
152
     */
153 12
    private function initializeLogger()
154
    {
155 12
        $logger = new Logger('Easemob');
156
157 12
        if ($this['config']['debug']) {
158
            $logger->pushHandler(new NullHandler());
159 12
        } elseif ($logFile = $this['config']['log.file']) {
160 12
            $logger->pushHandler(new StreamHandler(
161 12
                $logFile,
162 12
                $this['config']->get('log.level') ?: Logger::WARNING
163 12
            ));
164 12
        }
165
166 12
        Log::setLogger($logger);
167 12
    }
168
169
    /**
170
     * @param string $name
171
     *
172
     * @return mixed
173
     */
174 3
    public function __get($name)
175
    {
176 3
        return $this->offsetGet($name);
177
    }
178
179
    /**
180
     * @param string $name
181
     * @param mixed  $value
182
     */
183
    public function __set($name, $value)
184
    {
185
        $this->offsetSet($name, $value);
186
    }
187
188
    /**
189
     * @param string $name
190
     *
191
     * @return bool
192
     */
193
    public function __isset($name)
194
    {
195
        return $this->offsetExists($name);
196
    }
197
198
    /**
199
     * @param string $name
200
     */
201
    public function __unset($name)
202
    {
203
        $this->offsetUnset($name);
204
    }
205
}
206