Issues (4)

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.

controllers/Command.php (2 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
 * @package CLI
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2018, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\cli\controllers;
11
12
use gplcart\core\CliController;
13
use gplcart\core\traits\Listing as ListingTrait;
14
use InvalidArgumentException;
15
16
/**
17
 * Parent controller
18
 */
19
class Command extends CliController
20
{
21
22
    use ListingTrait;
23
24
    /**
25
     * Output formatted data
26
     * @param mixed $data
27
     * @param null|string $default
28
     * @return null
29
     */
30
    protected function outputFormat($data, $default = null)
31
    {
32
        switch ($this->getParam(array('f'), $default)) {
33
            case 'print-r':
34
                $this->line(print_r($data, true));
35
                break;
36
            case 'var-export':
37
                $this->line(var_export($data, true));
38
                break;
39
            case 'json':
40
                $this->line(json_encode($data, JSON_PRETTY_PRINT));
41
                break;
42
            case 'var-dump':
43
                ob_start();
44
                var_dump($data);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($data); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
45
                $this->line(ob_get_clean());
46
                break;
47
            default:
48
                return null; // Pass to table formatter
49
        }
50
51
        $this->output();
52
    }
53
54
    /**
55
     * Output simple table
56
     * @param mixed $data
57
     * @param array $header
58
     */
59
    protected function outputFormatTable($data, array $header)
60
    {
61
        if (!is_array($data)) {
62
            $this->line(print_r($data, true));
63
            $this->output();
64
        }
65
66
        foreach ($data as &$row) {
0 ignored issues
show
The expression $data of type object|integer|double|string|null|boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
67
68
            if (!is_array($row)) {
69
                $this->errorAndExit($this->text('Unexpected table row format'));
70
            }
71
72
            ksort($row);
73
74
            foreach ($row as &$item) {
75
                if (is_array($item)) {
76
                    $item = '-- Array ' . count($item) . ' items --';
77
                }
78
            }
79
        }
80
81
        if (empty($data)) {
82
            $this->line($this->text('No results'));
83
        } else {
84
            array_unshift($data, $header);
85
            $this->table($data);
86
        }
87
88
        $this->output();
89
    }
90
91
    /**
92
     * Returns an array of limits form the limit option or a default value
93
     * @param array $default_limit
94
     * @return array
95
     */
96
    protected function getLimit(array $default_limit = array())
97
    {
98
        if (empty($default_limit)) {
99
            $default_limit = $this->config->get('module_cli_limit', array(0, 100));
100
        }
101
102
        $limit = $this->getParam('l');
103
104
        if (!isset($limit) || !is_numeric($limit)) {
105
            return $default_limit;
106
        }
107
108
        $exploded = explode(',', $limit, 2);
109
110
        if (count($exploded) == 1) {
111
            array_unshift($exploded, 0);
112
        }
113
114
        return $exploded;
115
    }
116
117
    /**
118
     * Limits an array of items
119
     * @param array $array
120
     * @param array $default_limit
121
     */
122
    protected function limitArray(&$array, array $default_limit = array())
123
    {
124
        if (is_array($array)) {
125
            $this->limitList($array, $this->getLimit($default_limit));
126
        }
127
    }
128
129
    /**
130
     * Explode a string using a separator character
131
     * @param string $value
132
     * @param string|null $separator
133
     * @return array
134
     */
135
    protected function explodeList($value, $separator = null)
136
    {
137
        if (is_array($value)) {
138
            return $value;
139
        }
140
141
        if ($value === '' || !is_string($value)) {
142
            return array();
143
        }
144
145
        if (!isset($separator)) {
146
            $separator = $this->config->get('module_cli_list_separator', '|');
147
        }
148
149
        return array_map('trim', explode($separator, $value));
150
    }
151
152
    /**
153
     * Convert a submitted JSON string into an array or FALSE on error
154
     * @param string $field
155
     */
156
    protected function setSubmittedJson($field)
157
    {
158
        $json = $this->getSubmitted($field);
159
160
        if (isset($json)) {
161
            $decoded = json_decode($json, true);
162
            if (json_last_error() === JSON_ERROR_NONE) {
163
                $this->setSubmitted($field, $decoded);
164
            } else {
165
                $decoded = json_decode(base64_decode($json), true);
166
                if (json_last_error() !== JSON_ERROR_NONE) {
167
                    throw new InvalidArgumentException('Failed to decode the submitted JSON string');
168
                }
169
                $this->setSubmitted($field, $decoded);
170
            }
171
        }
172
    }
173
174
    /**
175
     * Converts a submitted string into an array using a character as an separator
176
     * @param $field
177
     */
178
    protected function setSubmittedList($field)
179
    {
180
        $value = $this->getSubmitted($field);
181
182
        if (isset($value)) {
183
            $this->setSubmitted($field, $this->explodeList($value));
184
        }
185
    }
186
187
    /**
188
     * Validate prompt input when dealing with multiple values separated by a list character
189
     * @param string $field
190
     * @param string $label
191
     * @param string $validator
192
     * @param null|string $default
193
     */
194
    protected function validatePromptList($field, $label, $validator, $default = null)
195
    {
196
        $input = $this->prompt($label, $default);
197
198
        if ($this->isValidInput($this->explodeList($input), $field, $validator)) {
199
            $this->setSubmitted($field, $input);
200
        } else {
201
            $this->errors();
202
            $this->validatePromptList($field, $label, $validator, $default);
203
        }
204
    }
205
206
}
207