Issues (17)

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

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 Monospice\LaravelRedisSentinel;
4
5
use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster;
6
use Illuminate\Cache\RedisStore;
7
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
8
use Illuminate\Queue\Connectors\RedisConnector;
9
use Illuminate\Session\CacheBasedSessionHandler;
10
use Illuminate\Support\Arr;
11
use Illuminate\Support\ServiceProvider;
12
use Monospice\LaravelRedisSentinel\Configuration\Loader as ConfigurationLoader;
13
use Monospice\LaravelRedisSentinel\Contracts\Factory;
14
use Monospice\LaravelRedisSentinel\Horizon\HorizonServiceProvider;
15
use Monospice\LaravelRedisSentinel\Manager\VersionedManagerFactory;
16
17
/**
18
 * Registers the "redis-sentinel" driver as an available driver for Laravel's
19
 * cache, session, and queue services and loads the appropriate configuration.
20
 *
21
 * @category Package
22
 * @package  Monospice\LaravelRedisSentinel
23
 * @author   Cy Rossignol <[email protected]>
24
 * @license  See LICENSE file
25
 * @link     https://github.com/monospice/laravel-redis-sentinel-drivers
26
 */
27
class RedisSentinelServiceProvider extends ServiceProvider
28
{
29
    /**
30
     * Loads the package's configuration and provides configuration values.
31
     *
32
     * @var ConfigurationLoader
33
     */
34
    protected $config;
35
36
    /**
37
     * Records whether this provider has already been booted (eg. via auto-boot)
38
     *
39
     * @var boolean
40
     */
41
    private $isBooted = false;
42
43
    /**
44
     * Boot the service by registering extensions with Laravel's cache, queue,
45
     * and session managers for the "redis-sentinel" driver.
46
     *
47
     * @return void
48
     */
49
    public function boot()
50
    {
51
        // If we configured the package to boot its services immediately after
52
        // the registration phase (auto-boot), don't boot the provider again:
53
        if ($this->isBooted) {
54
            return;
55
        }
56
57
        $this->bootComponentDrivers();
58
59
        // If we want Laravel's Redis API to use Sentinel, we'll remove the
60
        // "redis" service from the deferred services in the container:
61
        if ($this->config->shouldOverrideLaravelRedisApi) {
62
            $this->removeDeferredRedisServices();
63
        }
64
65
        if ($this->config->shouldIntegrateHorizon) {
66
            $horizon = new HorizonServiceProvider($this->app, $this->config);
67
            $horizon->register();
68
            $horizon->boot();
69
        }
70
71
        $this->isBooted = true;
72
    }
73
74
    /**
75
     * Bind the "redis-sentinel" database driver to the application service
76
     * container.
77
     *
78
     * @return void
79
     */
80
    public function register()
81
    {
82
        $this->config = ConfigurationLoader::load($this->app);
83
84
        $this->registerServices();
85
86
        // If we want Laravel's Redis API to use Sentinel, we'll return an
87
        // instance of the RedisSentinelManager when requesting the "redis"
88
        // service:
89
        if ($this->config->shouldOverrideLaravelRedisApi) {
90
            $this->registerOverrides();
91
        }
92
93
        // If we explicitly configured the package to auto-boot, run the boot
94
        // phase now to bind the packages drivers. This overcomes issues with
95
        // other third-party packages that don't follow Laravel's convention:
96
        if ($this->config->shouldAutoBoot()) {
97
            $this->boot();
98
        }
99
    }
100
101
    /**
102
     * Register the core Redis Sentinel connection manager.
103
     *
104
     * @return void
105
     */
106
    protected function registerServices()
107
    {
108
        $this->app->singleton('redis-sentinel', function () {
109
            return VersionedManagerFactory::make($this->app, $this->config);
110
        });
111
112
        $this->app->singleton('redis-sentinel.manager', function ($app) {
113
            return $app->make('redis-sentinel')->getVersionedManager();
114
        });
115
116
        $this->app->alias('redis-sentinel', Factory::class);
117
    }
118
119
    /**
120
     * Replace the standard Laravel Redis service with the Redis Sentinel
121
     * database driver so all Redis operations use Sentinel connections.
122
     *
123
     * @return void
124
     */
125
    protected function registerOverrides()
126
    {
127
        $this->app->singleton('redis', function ($app) {
128
            return $app->make('redis-sentinel');
129
        });
130
131
        $this->app->bind('redis.connection', function ($app) {
132
            return $app->make('redis-sentinel.manager')->connection();
133
        });
134
    }
135
136
    /**
137
     * Extend each of the Laravel services this package supports with the
138
     * corresponding 'redis-sentinel' driver.
139
     *
140
     * @return void
141
     */
142
    protected function bootComponentDrivers()
143
    {
144
        $this->addRedisSentinelBroadcaster();
145
        $this->addRedisSentinelCacheStore();
146
147
        // This package's Horizon service provider will set up the queue
148
        // connector a bit differently, so we don't need to do it twice:
149
        if (! $this->config->shouldIntegrateHorizon) {
150
            $this->addRedisSentinelQueueConnector();
151
        }
152
153
        // Since version 5.2, Lumen does not include support for sessions by
154
        // default, so we'll only register the session handler if enabled:
155
        if ($this->config->supportsSessions) {
156
            $this->addRedisSentinelSessionHandler();
157
        }
158
    }
159
160
    /**
161
     * Remove the standard Laravel Redis service from the bound deferred
162
     * services so they don't overwrite Redis Sentinel registrations.
163
     *
164
     * @return void
165
     */
166
    protected function removeDeferredRedisServices()
167
    {
168
        if ($this->config->isLumen) {
169
            return;
170
        }
171
172
        $deferredServices = $this->app->getDeferredServices();
173
174
        unset($deferredServices['redis']);
175
        unset($deferredServices['redis.connection']);
176
177
        $this->app->setDeferredServices($deferredServices);
178
    }
179
180
    /**
181
     * Add "redis-sentinel" as an available broadcaster option to the Laravel
182
     * event broadcasting manager.
183
     *
184
     * @return void
185
     */
186
    protected function addRedisSentinelBroadcaster()
187
    {
188
        $this->app->make(BroadcastFactory::class)
189
            ->extend('redis-sentinel', function ($app, $conf) {
190
                $redis = $app->make('redis-sentinel.manager');
191
                $connection = Arr::get($conf, 'connection', 'default');
192
193
                return new RedisBroadcaster($redis, $connection);
194
            });
195
    }
196
197
    /**
198
     * Add "redis-sentinel" as an available cache store option to the Laravel
199
     * cache manager.
200
     *
201
     * @return void
202
     */
203
    protected function addRedisSentinelCacheStore()
204
    {
205
        $cache = $this->app->make('cache');
206
207
        $cache->extend('redis-sentinel', function ($app, $conf) use ($cache) {
208
            $redis = $app->make('redis-sentinel.manager');
209
            $prefix = $app->make('config')->get('cache.prefix');
210
            $connection = Arr::get($conf, 'connection', 'default');
211
            $store = new RedisStore($redis, $prefix, $connection);
212
213
            return $cache->repository($store);
214
        });
215
    }
216
217
    /**
218
     * Add "redis-sentinel" as an available driver option to the Laravel
219
     * session manager.
220
     *
221
     * @return void
222
     */
223
    protected function addRedisSentinelSessionHandler()
224
    {
225
        $this->app->make('session')->extend('redis-sentinel', function ($app) {
226
            $cacheDriver = clone $app->make('cache')->driver('redis-sentinel');
227
            $minutes = $this->config->get('session.lifetime');
228
            $connection = $this->config->get('session.connection');
229
230
            $cacheDriver->getStore()->setConnection($connection);
231
232
            return new CacheBasedSessionHandler($cacheDriver, $minutes);
233
        });
234
    }
235
236
    /**
237
     * Add "redis-sentinel" as an available queue connection driver option to
238
     * the Laravel queue manager.
239
     *
240
     * @return void
241
     */
242 View Code Duplication
    protected function addRedisSentinelQueueConnector()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
243
    {
244
        $this->app->make('queue')->extend('redis-sentinel', function () {
245
            $redis = $this->app->make('redis-sentinel.manager');
246
247
            return new RedisConnector($redis);
248
        });
249
    }
250
}
251