Issues (21)

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/Console/ApiListCommand.php (3 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
declare(strict_types=1);
4
5
namespace PCextreme\Cloudstack\Console;
6
7
use PCextreme\Cloudstack\Client;
8
use Symfony\Component\Cache\Simple\FilesystemCache;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Helper\ProgressBar;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\Question;
14
15
class ApiListCommand extends Command
16
{
17
    /**
18
     * @var FilesystemCache
19
     */
20
    private $cache;
21
22
    /**
23
     * Configures the current command.
24
     *
25
     * @return void
26
     */
27
    protected function configure()
28
    {
29
        $this->setName('api:list')
30
            ->setDescription('Generate API list cache.')
31
            ->setHelp("This will generate the API list cache file usign the 'listApis' command.");
32
    }
33
34
    /**
35
     * Executes the current command.
36
     *
37
     * @param  InputInterface  $input
38
     * @param  OutputInterface $output
39
     * @return void
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output) : void
42
    {
43
        $urlApi    = $this->askUrlApi($input, $output);
44
        $apiKey    = $this->askApiKey($input, $output);
45
        $secretKey = $this->askSecretKey($input, $output);
46
47
        $output->writeLn('');
48
        $output->writeLn("<info>Processing API list. Please Wait...</info>");
49
50
        $client = new Client([
51
            'urlApi'    => $urlApi,
52
            'apiKey'    => $apiKey,
53
            'secretKey' => $secretKey,
54
        ]);
55
56
        $command = 'listApis';
57
        $method  = $client->getCommandMethod($command);
58
        $url     = $client->getCommandUrl($command, []);
59
        $request = $client->getRequest($method, $url, []);
60
61
        $list = $client->getResponse($request);
62
63
        // We expect an array from the getResponse method, when this returns
64
        // with a string we most likely got a server error.
65
        if (is_string($list)) {
66
            throw new \RuntimeException(sprintf(
67
                "Invalid API response, received: %s",
68
                $list
69
            ));
70
        }
71
72
        $this->processList($output, $list);
73
    }
74
75
    /**
76
     * Ask for URL API.
77
     *
78
     * @param  InputInterface  $input
79
     * @param  OutputInterface $output
80
     * @return string
81
     */
82
    protected function askUrlApi(InputInterface $input, OutputInterface $output) : string
83
    {
84
        $question = new Question(
85
            'Enter target API url [default: https://api.auroracompute.eu/ams]: ',
86
            'https://api.auroracompute.eu/ams'
87
        );
88
89
        return $this->getHelper('question')->ask($input, $output, $question);
90
    }
91
92
    /**
93
     * Ask for API key.
94
     *
95
     * @param  InputInterface  $input
96
     * @param  OutputInterface $output
97
     * @return string
98
     */
99 View Code Duplication
    protected function askApiKey(InputInterface $input, OutputInterface $output) : string
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...
100
    {
101
        $question = (new Question('Enter API key: '))
102
            ->setValidator(function ($answer) {
103
                if (is_null($answer)) {
104
                    throw new \InvalidArgumentException("API key can't be null.");
105
                }
106
107
                return $answer;
108
            })
109
            ->setMaxAttempts(2);
110
111
        return $this->getHelper('question')->ask($input, $output, $question);
112
    }
113
114
    /**
115
     * Ask for secret key.
116
     *
117
     * @param  InputInterface  $input
118
     * @param  OutputInterface $output
119
     * @return string
120
     */
121 View Code Duplication
    protected function askSecretKey(InputInterface $input, OutputInterface $output) : string
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...
122
    {
123
        $question = (new Question('Enter secret key: '))
124
            ->setValidator(function ($answer) {
125
                if (is_null($answer)) {
126
                    throw new \InvalidArgumentException("Secret key can't be null.");
127
                }
128
129
                return $answer;
130
            })
131
            ->setMaxAttempts(2);
132
133
        return $this->getHelper('question')->ask($input, $output, $question);
134
    }
135
136
    /**
137
     * Dump cache file of APIs list.
138
     *
139
     * @param  OutputInterface $output
140
     * @param  array           $list
141
     * @return void
142
     */
143
    protected function processList(OutputInterface $output, array $list = []) : void
144
    {
145
        if (empty($list)) {
146
            throw new \RuntimeException("API list is empty.");
147
        }
148
149
        $progress = new ProgressBar($output, $list['listapisresponse']['count']);
150
        $progress->start();
151
152
        $commands = [];
153
154
        foreach ($list['listapisresponse']['api'] as $api) {
155
            $commands = array_merge($commands, $this->parseCommand($api));
156
157
            $progress->advance();
158
        }
159
160
        $this->cache()->set('api.list', $commands);
161
162
        $progress->finish();
163
    }
164
165
    /**
166
     * Parse command data into expected structure
167
     * @param  array $command
168
     * @return array
169
     */
170
    protected function parseCommand(array $command) : array
171
    {
172
        $params = [];
173
174
        foreach ($command['params'] as $param) {
175
            $params = array_merge($params, [
176
                $param['name'] => [
177
                    'description' => $param['description'],
178
                    'required' => $param['required'],
179
                    'type' => $param['type'],
180
                ]
181
            ]);
182
        }
183
184
        return [$command['name'] => [
185
            'description' => $command['description'],
186
            'isasync'     => $command['isasync'],
187
            'params'      => $params
188
        ]];
189
    }
190
191
    /**
192
     * Get cache driver instance
193
     * @return FilesystemCache
194
     */
195 View Code Duplication
    private function cache() : FilesystemCache
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...
196
    {
197
        if (! isset($this->cache)) {
198
            $this->cache = new FilesystemCache('', 0, __DIR__.'/../../cache');
199
        }
200
201
        return $this->cache;
202
    }
203
}
204