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/KeyManager.php (5 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 Bytesfield\KeyManager;
4
5
use Bytesfield\KeyManager\Models\ApiCredential;
6
use Bytesfield\KeyManager\Models\Client;
7
use Bytesfield\KeyManager\Traits\ApiResponse;
8
use Illuminate\Http\JsonResponse;
9
10
class KeyManager implements KeyManagerInterface
11
{
12
    use ApiResponse;
13
14
    /**
15
     * Create a new Client with Api credentials.
16
     *
17
     * @param string $name
18
     * @param string $type
19
     * @param string $status
20
     * @return \Illuminate\Http\JsonResponse
21
     */
22
    public function createClient(string $name, string $type, string $status = 'active'): JsonResponse
23
    {
24
        if (! in_array($status, [ApiCredential::STATUSES['ACTIVE'], ApiCredential::STATUSES['SUSPENDED']])) {
25
            return $this->error('Status must be either active or suspended');
26
        }
27
28
        $client = Client::create([
29
            'name' => $name,
30
            'type' => $type,
31
            'status' => $status,
32
        ]);
33
34
        $client->apiCredential()->create(ApiCredential::generateKeyPairArray());
35
36
        return $this->success('Client created successfully', $client->toArray());
37
    }
38
39
    /**
40
     * Get client's private key.
41
     *
42
     * @param int $client_id
43
     * @return \Illuminate\Http\JsonResponse
44
     */
45 View Code Duplication
    public function getPrivateKey(int $client_id): JsonResponse
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...
46
    {
47
        $client = Client::with('apiCredential')->where('id', $client_id)->first();
48
49
        if (! $client) {
50
            return $this->error("No client found with id $client_id");
51
        }
52
53
        return $this->success('Key retrieved successfully', ['key' => $client->apiCredential->private_key]);
54
    }
55
56
    /**
57
     * Change Client's public and private keys.
58
     *
59
     * @param int $client_id
60
     * @return \Illuminate\Http\JsonResponse
61
     */
62 View Code Duplication
    public function changeKeys(int $client_id): JsonResponse
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...
63
    {
64
        $key = ApiCredential::where('key_client_id', $client_id)->first();
65
66
        if (! $key) {
67
            return $this->error('Client information not found');
68
        }
69
70
        $key->update(ApiCredential::generateKeyPairArray());
71
72
        return $this->success('Api Keys successfully changed', ['key' => $key->private_key]);
73
    }
74
75
    /**
76
     * Suspend Client's Account.
77
     *
78
     * @param int $client_id
79
     * @return \Illuminate\Http\JsonResponse
80
     */
81
    public function suspendClient(int $client_id): JsonResponse
82
    {
83
        $client = Client::find($client_id);
84
85
        if (! $client) {
86
            return $this->error("No client found with id $client_id");
87
        }
88
89
        $client->update([
90
            'status' => ApiCredential::STATUSES['SUSPENDED'],
91
        ]);
92
93
        return $this->success('Client successfully suspended');
94
    }
95
96
    /**
97
     * Activate Client's Account.
98
     *
99
     * @param int $client_id
100
     * @return \Illuminate\Http\JsonResponse
101
     */
102 View Code Duplication
    public function activateClient(int $client_id): JsonResponse
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...
103
    {
104
        $client = Client::find($client_id);
105
106
        if (! $client) {
107
            return $this->error("No client found with id $client_id");
108
        }
109
110
        $client->update([
111
            'status' => ApiCredential::STATUSES['ACTIVE'],
112
        ]);
113
114
        return $this->success('Client successfully activated');
115
    }
116
117
    /**
118
     * Suspend Client's Api Credential.
119
     *
120
     * @param int $client_id
121
     * @return \Illuminate\Http\JsonResponse
122
     */
123 View Code Duplication
    public function suspendApiCredential(int $client_id): JsonResponse
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...
124
    {
125
        $key = ApiCredential::where('key_client_id', $client_id)->first();
126
127
        if (! $key) {
128
            return $this->error('Client information not found');
129
        }
130
131
        $key->update([
132
            'status' => ApiCredential::STATUSES['SUSPENDED'],
133
        ]);
134
135
        return $this->success('ApiCredential successfully suspended');
136
    }
137
138
    /**
139
     * Activate Client's Api Credential.
140
     *
141
     * @param int $client_id
142
     * @return \Illuminate\Http\JsonResponse
143
     */
144 View Code Duplication
    public function activateApiCredential(int $client_id): JsonResponse
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...
145
    {
146
        $key = ApiCredential::where('key_client_id', $client_id)->first();
147
148
        if (! $key) {
149
            return $this->error('Client information not found');
150
        }
151
152
        $key->update([
153
            'status' => ApiCredential::STATUSES['ACTIVE'],
154
        ]);
155
156
        return $this->success('ApiCredential successfully activated');
157
    }
158
}
159