Issues (34)

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/KeyManagerServiceProvider.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
namespace Bytesfield\KeyManager;
4
5
use Bytesfield\KeyManager\Commands\ActivateApiCredentialCommand;
6
use Bytesfield\KeyManager\Commands\ActivateClientCommand;
7
use Bytesfield\KeyManager\Commands\ChangeKeysCommand;
8
use Bytesfield\KeyManager\Commands\CreateClientCommand;
9
use Bytesfield\KeyManager\Commands\GenerateEncryptionKeyCommand;
10
use Bytesfield\KeyManager\Commands\GetApiKeyCommand;
11
use Bytesfield\KeyManager\Commands\InstallKeyManagerCommand;
12
use Bytesfield\KeyManager\Commands\SuspendApiCredentialCommand;
13
use Bytesfield\KeyManager\Commands\SuspendClientCommand;
14
use Bytesfield\KeyManager\Exceptions\Handler;
15
use Bytesfield\KeyManager\Middlewares\AuthenticateClient;
16
use Illuminate\Routing\Router;
17
use Illuminate\Support\ServiceProvider;
18
use ParagonIE\CipherSweet\Backend\ModernCrypto;
19
use ParagonIE\CipherSweet\CipherSweet;
20
use ParagonIE\CipherSweet\KeyProvider\StringProvider;
21
22
class KeyManagerServiceProvider extends ServiceProvider
23
{
24
    /**
25
     * Register services.
26
     *
27
     * @return void
28
     */
29
    public function register()
30
    {
31
        $this->registerCipherSweet();
32
        $this->app->singleton(KeyManagerInterface::class, KeyManager::class);
33
34
        $this->app->singleton(
35
            \Illuminate\Contracts\Debug\ExceptionHandler::class,
36
            Handler::class
37
        );
38
39
        $this->mergeConfigFrom(__DIR__.'/config/keymanager.php', 'keymanager');
40
41
        $this->app->bind('key-manager', function ($app) {
42
            return new KeyManager($app->request);
0 ignored issues
show
The call to KeyManager::__construct() has too many arguments starting with $app->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
        });
44
        $this->app->alias('key-manager', "Bytesfield\KeyManager\KeyManager");
45
    }
46
47
    /**
48
     * Bootstrap services.
49
     *
50
     * @return void
51
     */
52
    public function boot()
53
    {
54
        //Loads Package Migration
55
        $this->loadMigrationsFrom(__DIR__.'/database/migrations');
56
57
        //Register Package Middleware
58
        $router = $this->app->make(Router::class);
59
        $router->aliasMiddleware('auth.client', AuthenticateClient::class);
60
61
        if ($this->app->runningInConsole()) {
62
63
            //Publishes Package Config
64
            $this->publishes([
65
                __DIR__.'/config/keymanager.php' => config_path('keymanager.php'),
66
            ], 'config');
67
68
            //Publishes Migrations
69
            if (! class_exists('CreateKeyClientsTable') && ! class_exists('CreateKeyApiCredentialsTable')) {
70
                $this->publishes([
71
                    __DIR__.'/database/migrations/2020_12_19_075709_create_key_clients_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'1'.'_create_key_clients_table.php'),
72
                    __DIR__.'/database/migrations/2020_12_19_075855_create_key_api_credentials_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'2'.'_create_key_api_credentials_table.php'),
73
                ], 'migrations');
74
            }
75
76
            //Register Package Console Commands
77
            $this->commands([
78
                GenerateEncryptionKeyCommand::class,
79
                CreateClientCommand::class,
80
                GetApiKeyCommand::class,
81
                ChangeKeysCommand::class,
82
                SuspendClientCommand::class,
83
                ActivateClientCommand::class,
84
                SuspendApiCredentialCommand::class,
85
                ActivateApiCredentialCommand::class,
86
                InstallKeyManagerCommand::class,
87
88
            ]);
89
        }
90
    }
91
92
    /**
93
     * Register CipherSweet library.
94
     *
95
     * @return void
96
     */
97
    private function registerCipherSweet(): void
98
    {
99
        $this->app->singleton(CipherSweet::class, function () {
100
            $key = config('keymanager.api_encryption_key');
101
102
            if (empty($key)) {
103
                throw new \RuntimeException(
104
                    'Encryption key for key manager service is not specified.'
105
                );
106
            }
107
108
            return new CipherSweet(new StringProvider($key), new ModernCrypto());
109
        });
110
    }
111
}
112