Issues (5)

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.

handlers/Download.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 Installer
5
 * @author Iurii Makukh
6
 * @copyright Copyright (c) 2017, Iurii Makukh
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\installer\handlers;
11
12
use gplcart\core\models\FileTransfer;
13
use gplcart\modules\installer\models\Install;
14
15
/**
16
 * Handler for Installer module
17
 */
18
class Download
19
{
20
21
    /**
22
     * Language model instance
23
     * @var \gplcart\core\models\Language $language
24
     */
25
    protected $language;
26
27
    /**
28
     * Installer model class instance
29
     * @var \gplcart\modules\installer\models\Install $install
30
     */
31
    protected $install;
32
33
    /**
34
     * File transfer model instance
35
     * @var \gplcart\core\models\FileTransfer $file_transfer
36
     */
37
    protected $file_transfer;
38
39
    /**
40
     * An array of errors
41
     * @var array
42
     */
43
    protected $errors = array();
44
45
    /**
46
     * An array of the current job
47
     * @var array
48
     */
49
    protected $job = array();
50
51
    /**
52
     * The current processing URL
53
     * @var string
54
     */
55
    protected $data_url;
56
57
    /**
58
     * Download constructor.
59
     * @param FileTransfer $file_transfer
60
     * @param Install $install
61
     */
62
    public function __construct(FileTransfer $file_transfer, Install $install)
63
    {
64
        $this->install = $install;
65
        $this->file_transfer = $file_transfer;
66
    }
67
68
    /**
69
     * Processes one job iteration
70
     * @param array $job
71
     */
72
    public function process(array &$job)
73
    {
74
        $this->job = &$job;
75
        $this->errors = array();
76
77
        if (empty($this->job['data']['sources'][$this->job['done']])) {
78
            $this->job['status'] = false;
79
            $this->job['done'] = $this->job['total'];
80
        } else {
81
            $this->install();
82
            $this->job['done']++;
83
            $this->job['errors'] += $this->countErrors();
84
        }
85
    }
86
87
    /**
88
     * Install a module
89
     * @return boolean
90
     */
91
    protected function install()
92
    {
93
        $file = $this->download();
94
95
        if (empty($file)) {
96
            return false;
97
        }
98
99
        $result = $this->install->fromZip($file);
0 ignored issues
show
It seems like $file defined by $this->download() on line 93 can also be of type boolean; however, gplcart\modules\installe...dels\Install::fromZip() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
100
101
        if ($result !== true) {
102
            $this->setError($result);
0 ignored issues
show
$result is of type null|boolean, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
            return false;
104
        }
105
106
        if ($this->install->isUpdate()) {
107
            $this->job['updated']++;
108
        } else {
109
            $this->job['inserted']++;
110
        }
111
112
        return true;
113
    }
114
115
    /**
116
     * Download a module file from a remote source
117
     * @return boolean|string
118
     */
119
    protected function download()
120
    {
121
        $this->data_url = $this->job['data']['sources'][$this->job['done']];
122
123
        $filename = md5($this->data_url);
124
        $destination = gplcart_file_private_module('installer', "$filename.zip", true);
125
        $result = $this->file_transfer->download($this->data_url, 'zip', $destination);
126
127
        if ($result === true) {
128
            return $this->file_transfer->getTransferred();
129
        }
130
131
        $this->setError($result);
132
        return false;
133
    }
134
135
    /**
136
     * Returns a total number of errors and logs them
137
     * @return integer
138
     */
139
    protected function countErrors()
140
    {
141
        $count = 0;
142
        foreach ($this->errors as $url => $errors) {
143
            $errors = array_filter($errors);
144
            $count += count($errors);
145
            $this->logErrors($url, $errors);
146
        }
147
        return $count;
148
    }
149
150
    /**
151
     * Logs all errors happened for the URL
152
     * @param integer $url
153
     * @param array $errors
154
     * @return boolean
155
     */
156
    protected function logErrors($url, array $errors)
157
    {
158
        $data = array($url, implode(PHP_EOL, $errors));
159
        return gplcart_file_csv($this->job['log']['errors'], $data);
160
    }
161
162
    /**
163
     * Sets a error
164
     * @param string|array $error
165
     */
166
    protected function setError($error)
167
    {
168
        settype($error, 'array');
169
        $existing = empty($this->errors[$this->data_url]) ? array() : $this->errors[$this->data_url];
170
        $this->errors[$this->data_url] = gplcart_array_merge($existing, $error);
171
    }
172
173
}
174