Issues (55)

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/QuotaServiceProvider.php (6 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
/**
4
 * This file is part of laravel-quota
5
 *
6
 * (c) David Faith <[email protected]>
7
 *
8
 * Full copyright and license information is available
9
 * in the LICENSE file distributed with this source code.
10
 */
11
12
namespace Projectmentor\Quota;
13
14
use bandwidthThrottle\tokenBucket\Rate;
15
use bandwidthThrottle\tokenBucket\TokenBucket;
16
use bandwidthThrottle\tokenBucket\BlockingConsumer;
17
use bandwidthThrottle\tokenBucket\storage\FileStorage;
18
19
use Illuminate\Foundation\Application as LaravelApplication;
20
use Laravel\Lumen\Application as LumenApplication;
21
22
use Illuminate\Support\ServiceProvider;
23
24
use Projectmentor\Quota\Factories\RateFactory;
25
use Projectmentor\Quota\Factories\FileStorageFactory;
26
use Projectmentor\Quota\Factories\TokenBucketFactory;
27
use Projectmentor\Quota\Factories\BlockingConsumerFactory;
28
29
use Projectmentor\Quota\Stubs\RateData;
30
use Projectmentor\Quota\Stubs\FileStorageData;
31
use Projectmentor\Quota\Stubs\TokenBucketData;
32
use Projectmentor\Quota\Stubs\BlockingConsumerData;
33
34
/**
35
 * This is the Quota service provider.
36
 *
37
 * "There is no need to bind classes into the container
38
 * if they do not depend on any interfaces"
39
 * - @See https://laravel.com/docs/5.2/container#binding
40
 *
41
 * Hence the base classes we are exposing from the library
42
 * Are not going to be registered here.
43
 *
44
 * We will register our factory classes and the Quota class
45
 * which will be used both as a `manager` and as a concrete
46
 * instance by leveraging  call_user_func_array(). In this
47
 * manner we will be able to access Quota as a singleton,
48
 * via a Facade, and it will maintain an array of rate-limiters
49
 * which we can retrieve when needed.
50
 * @See Projectmentor\Quota\Quota.php
51
 *
52
 *
53
 * @author David Faith <[email protected]>
54
 */
55
class QuotaServiceProvider extends ServiceProvider
56
{
57
    /**
58
     * Indicates if loading of the provider is deferred.
59
     *
60
     * @var bool
61
     */
62
    protected $defer = true;
63
64
    /**
65
     * Perform post-registration booting of services.
66
     *
67
     * @return void
68
     */
69 20
    public function boot()
70
    {
71 20
        $this->setupConfig();
72 20
    }
73
74
    /**
75
     * Setup the config
76
     *
77
     * @return void
78
     */
79 20
    protected function setupConfig()
80
    {
81 20
        $source = realpath(__DIR__.'/../config/quota.php');
82
83 20
        if ($this->app instanceof LaravelApplication &&
84 20
            $this->app->runningInConsole()) {
85 20
            $this->publishes([$source => config_path('quota.php')]);
86 20
        } elseif ($this->app instanceof LumenApplication) {
0 ignored issues
show
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
87
            $this->app->configure('quota');
88
        }
89
90 20
        $this->mergeConfigFrom($source, 'quota');
91 20
    }
92
93
    /**
94
     * Register any package services.
95
     *
96
     * @return void
97
     */
98 20
    public function register()
99
    {
100 20
        $this->bindInterfaces();
101 20
        $this->registerFactories();
102 20
    }
103
104
    /**
105
     * Bind interfaces to implementations.
106
     * @return void
107
     */
108 20
    public function bindInterfaces()
109
    {
110 20
        $this->app->when(RateFactory::class)
111 20
          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
112 20
          ->give(RateData::class);
113
114 20
        $this->app->when(FileStorageFactory::class)
115 20
          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
116 20
          ->give(FileStorageData::class);
117
118 20
        $this->app->when(TokenBucketFactory::class)
119 20
          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
120 20
          ->give(TokenBucketData::class);
121
122 20
        $this->app->when(BlockingConsumerFactory::class)
123 20
          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
124 20
          ->give(BlockingConsumerData::class);
125 20
    }
126
127
    /**
128
     * Register the factory classes.
129
     * @return void
130
     */
131 20
    protected function registerFactories()
132
    {
133
        $this->app->singleton('quota.factory.rate', function ($app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
134 1
            return new RateFactory;
135 20
        });
136
137
        $this->app->singleton('quota.factory.storage.file', function ($app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
138 1
            return new FileStorageFactory;
139 20
        });
140
141
        $this->app->singleton('quota.factory.tokenbucket', function ($app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142 2
            return new TokenBucketFactory;
143 20
        });
144
145 20
        $this->app->singleton('quota.factory.blockingconsumer', function ($app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146 1
            return new BlockingConsumerFactory;
147 20
        });
148
149 20
        $this->app->alias('quota.factory.rate', RateFactory::class);
150 20
        $this->app->alias('quota.factory.rate', FactoryInterface::class);
151
152 20
        $this->app->alias('quota.factory.storage.file', FileStorageFactory::class);
153 20
        $this->app->alias('quota.factory.storage.file', FactoryInterface::class);
154
155 20
        $this->app->alias('quota.factory.tokenbucket', TokenBucketFactory::class);
156 20
        $this->app->alias('quota.factory.tokenbucket', FactoryInterface::class);
157
158 20
        $this->app->alias('quota.factory.blockingconsumer', BlockingConsumerFactory::class);
159 20
        $this->app->alias('quota.factory.blockingconsumer', FactoryInterface::class);
160 20
    }
161
162
    /**
163
     * Get the services provided by this provider.
164
     *
165
     * @return string[]
166
     */
167 2
    public function provides()
168
    {
169
        return [
170 2
            'quota.factory.rate',
171 2
            'quota.factory.storage.file',
172 2
            'quota.factory.tokenbucket',
173
            'quota.factory.blockingconsumer'
174 2
        ];
175
    }
176
}
0 ignored issues
show
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
177