Completed
Push — development ( 6352e5...8bea34 )
by Nils
07:55
created

install.queries.php ➔ chmod_r()   D

Complexity

Conditions 9
Paths 13

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 13
nop 3
dl 0
loc 30
rs 4.909
c 0
b 0
f 0
1
<?php
2
/**
3
 * @file          install.queries.php
4
 * @author        Nils Laumaillé
5
 * @version       2.1.27
6
 * @copyright     (c) 2009-2017 Nils Laumaillé
7
 * @licensing     GNU AFFERO GPL 3.0
8
 * @link          http://www.teampass.net
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
require_once('../sources/SecureHandler.php');
15
session_start();
16
error_reporting(E_ERROR | E_PARSE);
17
header("Content-type: text/html; charset=utf-8");
18
$_SESSION['db_encoding'] = "utf8";
19
20
$_SESSION['CPM'] = 1;
21
22
function chmod_r($dir, $dirPermissions, $filePermissions)
23
{
24
    $dp = opendir($dir);
25
    $res = true;
26
    while ($file = readdir($dp)) {
27
        if (($file == ".") || ($file == "..")) {
28
            continue;
29
        }
30
31
        $fullPath = $dir."/".$file;
32
33
        if (is_dir($fullPath)) {
34
            if ($res = @chmod($fullPath, $dirPermissions)) {
35
                $res = @chmod_r($fullPath, $dirPermissions, $filePermissions);
36
            }
37
        } else {
38
            $res = chmod($fullPath, $filePermissions);
39
        }
40
        if (!$res) {
41
            closedir($dp);
42
            return false;
43
        }
44
    }
45
    closedir($dp);
46
    if (is_dir($dir) && $res) {
47
            $res = @chmod($dir, $dirPermissions);
48
    }
49
50
    return $res;
51
}
52
53
/**
54
 * genHash()
55
 *
56
 * Generate a hash for user login
57
 * @param string $password
58
 */
59 View Code Duplication
function bCrypt($password, $cost)
0 ignored issues
show
Duplication introduced by
This function 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...
60
{
61
    $salt = sprintf('$2y$%02d$', $cost);
62
    if (function_exists('openssl_random_pseudo_bytes')) {
63
        $salt .= bin2hex(openssl_random_pseudo_bytes(11));
64
    } else {
65
        $chars = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
66
        for ($i = 0; $i < 22; $i++) {
67
            $salt .= $chars[mt_rand(0, 63)];
68
        }
69
    }
70
    return crypt($password, $salt);
71
}
72
73
if (isset($_POST['type'])) {
74
    switch ($_POST['type']) {
75
        case "step_2":
76
            //decrypt
77
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
78
            $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
79
            $data = json_decode($json, true);
80
            $json = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
81
            $data = array_merge($data, array("activity" => $json));
82
            $json = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
83
            $data = array_merge($data, array("task" => $json));
84
85
            $abspath = str_replace('\\', '/', $data['root_path']);
86 View Code Duplication
            if (substr($abspath, strlen($abspath) - 1) == "/") {
87
                $abspath = substr($abspath, 0, strlen($abspath) - 1);
88
            }
89
            $_SESSION['abspath'] = $abspath;
90
            $_SESSION['url_path'] = $data['url_path'];
91
92
            if (isset($data['activity']) && $data['activity'] === "folder") {
93
                if (is_writable($abspath."/".$data['task']."/") === true) {
94
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 94

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
95
                } else {
96
                    echo '[{"error" : " Path '.$data['task'].' is not writable!", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : " Path ' . ...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 96

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
97
                }
98
                break;
99
            }
100
101 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "extension") {
102
                if (extension_loaded($data['task'])) {
103
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 103

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
104
                } else {
105
                    echo '[{"error" : " Extension '.$data['task'].' is not loaded!", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : " Extension...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 105

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
106
                }
107
                break;
108
            }
109
110 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "function") {
111
                if (function_exists($data['task'])) {
112
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 112

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
113
                } else {
114
                    echo '[{"error" : " Function '.$data['task'].' is not available!", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : " Function ...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 114

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
115
                }
116
                break;
117
            }
118
119 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "version") {
120
                if (version_compare(phpversion(), '5.5.0', '>=')) {
121
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 121

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
122
                } else {
123
                    echo '[{"error" : "PHP version '.phpversion().' is not OK (minimum is 5.5.0)", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "PHP versio...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 123

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
124
                }
125
                break;
126
            }
127
128 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "ini") {
129
                if (ini_get($data['task']) >= 60) {
130
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...$_POST['index'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 130

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
131
                } else {
132
                    echo '[{"error" : "PHP \"Maximum execution time\" is set to '.ini_get('max_execution_time').' seconds. Please try to set to 60s at least during installation.", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "PHP \\"Max...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 132

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
133
                }
134
                break;
135
            }
136
            break;
137
138
        case "step_3":
139
            //decrypt
140
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
141
            $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
142
            $data = json_decode($json, true);
143
            $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
144
            $db = json_decode($json, true);
145
146
            // launch
147
            if ($dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port'])) {
148
                // create temporary INSTALL mysqli table
149
                $mysqli_result = mysqli_query(
150
                    $dbTmp,
151
                    "CREATE TABLE IF NOT EXISTS `_install` (
152
                    `key` varchar(100) NOT NULL,
153
                    `value` varchar(500) NOT NULL
154
                    ) CHARSET=utf8;"
155
                );
156
                // store values
157 View Code Duplication
                foreach ($data as $key => $value) {
158
                    $_SESSION[$key] = $value;
159
                    $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'"));
160
                    if ($tmp[0] == 0 || empty($tmp[0])) {
161
                        mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
162
                    } else {
163
                        mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
164
                    }
165
                }
166
                $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = 'url_path'"));
167 View Code Duplication
                if ($tmp[0] == 0 || empty($tmp[0])) {
168
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('url_path', '", empty($_SESSION['url_path']) ? $db['url_path'] : $_SESSION['url_path'], "');");
169
                } else {
170
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['url_path']) ? $db['url_path'] : $_SESSION['url_path'], "' WHERE `key` = 'url_path';");
171
                }
172
                $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = 'abspath'"));
173 View Code Duplication
                if ($tmp[0] == 0 || empty($tmp[0])) {
174
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('abspath', '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'], "');");
175
                } else {
176
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'], "' WHERE `key` = 'abspath';");
177
                }
178
179
                echo '[{"error" : "", "result" : "Connection is successful", "multiple" : ""}]';
180 View Code Duplication
            } else {
181
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
182
            }
183
            mysqli_close($dbTmp);
184
            break;
185
186
        case "step_4":
187
            //decrypt
188
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
189
            $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
190
            $data = json_decode($json, true);
191
            $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
192
            $db = json_decode($json, true);
193
194
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
195
196
            // prepare data
197
            foreach ($data as $key => $value) {
198
                $data[$key] = str_replace(array('&quot;', '&#92;'), array('""', '\\\\'), $value);
199
            }
200
201
            // check skpath
202
            if (empty($data['sk_path'])) {
203
                $data['sk_path'] = $_SESSION['abspath']."/includes";
204
            } else {
205
                $data['sk_path'] = str_replace("&#92;", "/", $data['sk_path']);
206
            }
207
            if (substr($data['sk_path'], strlen($data['sk_path']) - 1) == "/" || substr($data['sk_path'], strlen($data['sk_path']) - 1) == "\"") {
208
                $data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path']) - 1);
209
            }
210
            if (is_dir($data['sk_path'])) {
211
                if (is_writable($data['sk_path'])) {
212
                    // store all variables in SESSION
213 View Code Duplication
                    foreach ($data as $key => $value) {
214
                        $_SESSION[$key] = $value;
215
                        $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'"));
216
                        if ($tmp[0] == 0 || empty($tmp[0])) {
217
                            mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
218
                        } else {
219
                            mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
220
                        }
221
                    }
222
                    echo '[{"error" : "", "result" : "Information stored", "multiple" : ""}]';
223
                } else {
224
                    echo '[{"error" : "The Directory must be writable!", "result" : "Information stored", "multiple" : ""}]';
225
                }
226
            } else {
227
                echo '[{"error" : "'.$data['sk_path'].' is not a Directory!", "result" : "Information stored", "multiple" : ""}]';
228
            }
229
            mysqli_close($dbTmp);
230
            break;
231
232
        case "step_5":
233
            //decrypt
234
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
235
            $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
236
            $task = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
237
            $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
238
            $db = json_decode($json, true);
239
240
            // launch
241
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
242
            $dbBdd = $db['db_bdd'];
243
            if ($dbTmp) {
244
                $mysqli_result = "";
245
246
                // read install variables
247
                $result = mysqli_query($dbTmp, "SELECT * FROM `_install`");
248
                while ($row = $result->fetch_array()) {
249
                    $var[$row[0]] = $row[1];
250
                }
251
252
                if ($activity === "table") {
253
                    //FORCE UTF8 DATABASE
254
                    mysqli_query($dbTmp, "ALTER DATABASE `".$dbBdd."` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
255
                    if ($task === "items") {
256
                        $mysqli_result = mysqli_query(
257
                            $dbTmp,
258
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items` (
259
                            `id` int(12) NOT null AUTO_INCREMENT,
260
                            `label` varchar(500) NOT NULL,
261
                            `description` text DEFAULT NULL,
262
                            `pw` text DEFAULT NULL,
263
                            `pw_iv` text DEFAULT NULL,
264
                            `pw_len` int(5) NOT NULL DEFAULT '0',
265
                            `url` varchar(500) DEFAULT NULL,
266
                            `id_tree` varchar(10) DEFAULT NULL,
267
                            `perso` tinyint(1) NOT null DEFAULT '0',
268
                            `login` varchar(200) DEFAULT NULL,
269
                            `inactif` tinyint(1) NOT null DEFAULT '0',
270
                            `restricted_to` varchar(200) DEFAULT NULL,
271
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
272
                            `email` varchar(100) DEFAULT NULL,
273
                            `notification` varchar(250) DEFAULT NULL,
274
                            `viewed_no` int(12) NOT null DEFAULT '0',
275
                            `complexity_level` varchar(3) NOT null DEFAULT '-1',
276
                            `auto_update_pwd_frequency` tinyint(2) NOT null DEFAULT '0',
277
                            `auto_update_pwd_next_date` varchar(100) NOT null DEFAULT '0',
278
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
279
                            PRIMARY KEY (`id`),
280
                            KEY    `restricted_inactif_idx` (`restricted_to`,`inactif`)
281
                            ) CHARSET=utf8;"
282
                        );
283
                    } elseif ($task === "log_items") {
284
                        $mysqli_result = mysqli_query(
285
                            $dbTmp,
286
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."log_items` (
287
                            `id_item` int(8) NOT NULL,
288
                            `date` varchar(50) NOT NULL,
289
                            `id_user` int(8) NOT NULL,
290
                            `action` varchar(250) NULL,
291
                            `raison` text NULL,
292
                            `raison_iv` text NULL,
293
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set'
294
                            ) CHARSET=utf8;"
295
                        );
296
                        // create index
297
                        mysqli_query(
298
                            $dbTmp,
299
                            "CREATE INDEX teampass_log_items_id_item_IDX ON ".$var['tbl_prefix']."log_items (id_item,date);"
300
                        );
301
                    } elseif ($task === "misc") {
302
                        $mysqli_result = mysqli_query(
303
                            $dbTmp,
304
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."misc` (
305
                            `id` int(12) NOT null AUTO_INCREMENT,
306
                            `type` varchar(50) NOT NULL,
307
                            `intitule` varchar(100) NOT NULL,
308
                            `valeur` varchar(500) NOT NULL,
309
                            PRIMARY KEY (`id`)
310
                            ) CHARSET=utf8;"
311
                        );
312
313
                        // include constants
314
                        require_once "../includes/config/include.php";
315
316
                        // prepare config file
317
                        $tp_config_file = "../includes/config/tp.config.php";
318 View Code Duplication
                        if (file_exists($tp_config_file)) {
319
                            if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
320
                                echo '[{"error" : "includes/config/tp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "includes/c...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 320

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
321
                                break;
322
                            } else {
323
                                unlink($tp_config_file);
324
                            }
325
                        }
326
                        $fh = fopen($tp_config_file, 'w');
327
                        $config_text = "<?php
328
global \$SETTINGS;
329
\$SETTINGS = array (";
330
331
                        // add by default settings
332
                        $aMiscVal = array(
333
                            array('admin', 'max_latest_items', '10'),
334
                            array('admin', 'enable_favourites', '1'),
335
                            array('admin', 'show_last_items', '1'),
336
                            array('admin', 'enable_pf_feature', '0'),
337
                            array('admin', 'log_connections', '0'),
338
                            array('admin', 'log_accessed', '1'),
339
                            array('admin', 'time_format', 'H:i:s'),
340
                            array('admin', 'date_format', 'd/m/Y'),
341
                            array('admin', 'duplicate_folder', '0'),
342
                            array('admin', 'item_duplicate_in_same_folder', '0'),
343
                            array('admin', 'duplicate_item', '0'),
344
                            array('admin', 'number_of_used_pw', '3'),
345
                            array('admin', 'manager_edit', '1'),
346
                            array('admin', 'cpassman_dir', $var['abspath']),
347
                            array('admin', 'cpassman_url', $var['url_path']),
348
                            array('admin', 'favicon', $var['url_path'].'/favicon.ico'),
349
                            array('admin', 'path_to_upload_folder', $var['abspath'].'/upload'),
350
                            array('admin', 'url_to_upload_folder', $var['url_path'].'/upload'),
351
                            array('admin', 'path_to_files_folder', $var['abspath'].'/files'),
352
                            array('admin', 'url_to_files_folder', $var['url_path'].'/files'),
353
                            array('admin', 'activate_expiration', '0'),
354
                            array('admin', 'pw_life_duration', '0'),
355
                            array('admin', 'maintenance_mode', '1'),
356
                            array('admin', 'enable_sts', '0'),
357
                            array('admin', 'encryptClientServer', '1'),
358
                            array('admin', 'cpassman_version', $k['version']),
359
                            array('admin', 'ldap_mode', '0'),
360
                            array('admin', 'ldap_type', '0'),
361
                            array('admin', 'ldap_suffix', '0'),
362
                            array('admin', 'ldap_domain_dn', '0'),
363
                            array('admin', 'ldap_domain_controler', '0'),
364
                            array('admin', 'ldap_user_attribute', '0'),
365
                            array('admin', 'ldap_ssl', '0'),
366
                            array('admin', 'ldap_tls', '0'),
367
                            array('admin', 'ldap_elusers', '0'),
368
                            array('admin', 'ldap_search_base', '0'),
369
                            array('admin', 'richtext', '0'),
370
                            array('admin', 'allow_print', '0'),
371
                            array('admin', 'roles_allowed_to_print', '0'),
372
                            array('admin', 'show_description', '1'),
373
                            array('admin', 'anyone_can_modify', '0'),
374
                            array('admin', 'anyone_can_modify_bydefault', '0'),
375
                            array('admin', 'nb_bad_authentication', '0'),
376
                            array('admin', 'utf8_enabled', '1'),
377
                            array('admin', 'restricted_to', '0'),
378
                            array('admin', 'restricted_to_roles', '0'),
379
                            array('admin', 'enable_send_email_on_user_login', '0'),
380
                            array('admin', 'enable_user_can_create_folders', '0'),
381
                            array('admin', 'insert_manual_entry_item_history', '0'),
382
                            array('admin', 'enable_kb', '0'),
383
                            array('admin', 'enable_email_notification_on_item_shown', '0'),
384
                            array('admin', 'enable_email_notification_on_user_pw_change', '0'),
385
                            array('admin', 'custom_logo', ''),
386
                            array('admin', 'custom_login_text', ''),
387
                            array('admin', 'default_language', 'english'),
388
                            array('admin', 'send_stats', '0'),
389
                            array('admin', 'send_statistics_items', 'stat_country;stat_users;stat_items;stat_items_shared;stat_folders;stat_folders_shared;stat_admins;stat_managers;stat_ro;stat_mysqlversion;stat_phpversion;stat_teampassversion;stat_languages;stat_kb;stat_suggestion;stat_customfields;stat_api;stat_2fa;stat_agses;stat_duo;stat_ldap;stat_syslog;stat_stricthttps;stat_fav;stat_pf;'),
390
                            array('admin', 'send_stats_time', time() - 2592000),
391
                            array('admin', 'get_tp_info', '1'),
392
                            array('admin', 'send_mail_on_user_login', '0'),
393
                            array('cron', 'sending_emails', '0'),
394
                            array('admin', 'nb_items_by_query', 'auto'),
395
                            array('admin', 'enable_delete_after_consultation', '0'),
396
                            array('admin', 'enable_personal_saltkey_cookie', '0'),
397
                            array('admin', 'personal_saltkey_cookie_duration', '31'),
398
                            array('admin', 'email_smtp_server', ''),
399
                            array('admin', 'email_smtp_auth', ''),
400
                            array('admin', 'email_auth_username', ''),
401
                            array('admin', 'email_auth_pwd', ''),
402
                            array('admin', 'email_port', ''),
403
                            array('admin', 'email_security', ''),
404
                            array('admin', 'email_server_url', ''),
405
                            array('admin', 'email_from', ''),
406
                            array('admin', 'email_from_name', ''),
407
                            array('admin', 'pwd_maximum_length', '40'),
408
                            array('admin', 'google_authentication', '0'),
409
                            array('admin', 'delay_item_edition', '0'),
410
                            array('admin', 'allow_import', '0'),
411
                            array('admin', 'proxy_ip', ''),
412
                            array('admin', 'proxy_port', ''),
413
                            array('admin', 'upload_maxfilesize', '10mb'),
414
                            array('admin', 'upload_docext', 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'),
415
                            array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png'),
416
                            array('admin', 'upload_pkgext', '7z,rar,tar,zip'),
417
                            array('admin', 'upload_otherext', 'sql,xml'),
418
                            array('admin', 'upload_imageresize_options', '1'),
419
                            array('admin', 'upload_imageresize_width', '800'),
420
                            array('admin', 'upload_imageresize_height', '600'),
421
                            array('admin', 'upload_imageresize_quality', '90'),
422
                            array('admin', 'use_md5_password_as_salt', '0'),
423
                            array('admin', 'ga_website_name', 'TeamPass for ChangeMe'),
424
                            array('admin', 'api', '0'),
425
                            array('admin', 'subfolder_rights_as_parent', '0'),
426
                            array('admin', 'show_only_accessible_folders', '0'),
427
                            array('admin', 'enable_suggestion', '0'),
428
                            array('admin', 'otv_expiration_period', '7'),
429
                            array('admin', 'default_session_expiration_time', '60'),
430
                            array('admin', 'duo', '0'),
431
                            array('admin', 'enable_server_password_change', '0'),
432
                            array('admin', 'ldap_object_class', '0'),
433
                            array('admin', 'bck_script_path', $var['abspath']."/backups"),
434
                            array('admin', 'bck_script_filename', 'bck_teampass'),
435
                            array('admin', 'syslog_enable', '0'),
436
                            array('admin', 'syslog_host', 'localhost'),
437
                            array('admin', 'syslog_port', '514'),
438
                            array('admin', 'manager_move_item', '0'),
439
                            array('admin', 'create_item_without_password', '0'),
440
                            array('admin', 'otv_is_enabled', '0'),
441
                            array('admin', 'agses_authentication_enabled', '0'),
442
                            array('admin', 'item_extra_fields', '0'),
443
                            array('admin', 'saltkey_ante_2127', 'none'),
444
                            array('admin', 'migration_to_2127', 'done'),
445
                            array('admin', 'files_with_defuse', 'done')
446
                        );
447
                        foreach ($aMiscVal as $elem) {
448
                            //Check if exists before inserting
449
                            $tmp = mysqli_num_rows(
450
                                mysqli_query(
451
                                    $dbTmp,
452
                                    "SELECT * FROM `".$var['tbl_prefix']."misc`
453
                                    WHERE type='".$elem[0]."' AND intitule='".$elem[1]."'"
454
                                )
455
                            );
456
                            if ($tmp[0] == 0) {
457
                                $queryRes = mysqli_query(
458
                                    $dbTmp,
459
                                    "INSERT INTO `".$var['tbl_prefix']."misc`
460
                                    (`type`, `intitule`, `valeur`) VALUES
461
                                    ('".$elem[0]."', '".$elem[1]."', '".
462
                                    str_replace("'", "", $elem[2])."');"
463
                                ); // or die(mysqli_error($dbTmp))
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
464
                            }
465
466
                            // append new setting in config file
467
                            $config_text .= "
468
    '".$elem[1]."' => '".str_replace("'", "", $elem[2])."',";
469
                        }
470
471
                        // write to config file
472
                        $result = fwrite(
473
                            $fh,
474
                            utf8_encode(
475
                                substr_replace($config_text, "", -1)."
476
);"
477
                            )
478
                        );
479
                        fclose($fh);
480
                    } elseif ($task === "nested_tree") {
481
                        $mysqli_result = mysqli_query(
482
                            $dbTmp,
483
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."nested_tree` (
484
                            `id` bigint(20) unsigned NOT null AUTO_INCREMENT,
485
                            `parent_id` int(11) NOT NULL,
486
                            `title` varchar(255) NOT NULL,
487
                            `nleft` int(11) NOT NULL DEFAULT '0',
488
                            `nright` int(11) NOT NULL DEFAULT '0',
489
                            `nlevel` int(11) NOT NULL DEFAULT '0',
490
                            `bloquer_creation` tinyint(1) NOT null DEFAULT '0',
491
                            `bloquer_modification` tinyint(1) NOT null DEFAULT '0',
492
                            `personal_folder` tinyint(1) NOT null DEFAULT '0',
493
                            `renewal_period` TINYINT(4) NOT null DEFAULT '0',
494
                            PRIMARY KEY (`id`),
495
                            UNIQUE KEY `id` (`id`),
496
                            KEY `nested_tree_parent_id` (`parent_id`),
497
                            KEY `nested_tree_nleft` (`nleft`),
498
                            KEY `nested_tree_nright` (`nright`),
499
                            KEY `nested_tree_nlevel` (`nlevel`),
500
                            KEY `personal_folder_idx` (`personal_folder`)
501
                            ) CHARSET=utf8;"
502
                        );
503
                    } elseif ($task === "rights") {
504
                        $mysqli_result = mysqli_query(
505
                            $dbTmp,
506
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."rights` (
507
                            `id` int(12) NOT null AUTO_INCREMENT,
508
                            `tree_id` int(12) NOT NULL,
509
                            `fonction_id` int(12) NOT NULL,
510
                            `authorized` tinyint(1) NOT null DEFAULT '0',
511
                            PRIMARY KEY (`id`)
512
                            ) CHARSET=utf8;"
513
                        );
514
                    } elseif ($task === "users") {
515
                        $mysqli_result = mysqli_query(
516
                            $dbTmp,
517
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."users` (
518
                            `id` int(12) NOT null AUTO_INCREMENT,
519
                            `login` varchar(50) NOT NULL,
520
                            `pw` varchar(400) NOT NULL,
521
                            `groupes_visibles` varchar(250) NOT NULL,
522
                            `derniers` text NULL,
523
                            `key_tempo` varchar(100) NULL,
524
                            `last_pw_change` varchar(30) NULL,
525
                            `last_pw` text NULL,
526
                            `admin` tinyint(1) NOT null DEFAULT '0',
527
                            `fonction_id` varchar(255) NULL,
528
                            `groupes_interdits` varchar(255) NULL,
529
                            `last_connexion` varchar(30) NULL,
530
                            `gestionnaire` int(11) NOT null DEFAULT '0',
531
                            `email` varchar(300) NOT NULL,
532
                            `favourites` varchar(300) NULL,
533
                            `latest_items` varchar(300) NULL,
534
                            `personal_folder` int(1) NOT null DEFAULT '0',
535
                            `disabled` tinyint(1) NOT null DEFAULT '0',
536
                            `no_bad_attempts` tinyint(1) NOT null DEFAULT '0',
537
                            `can_create_root_folder` tinyint(1) NOT null DEFAULT '0',
538
                            `read_only` tinyint(1) NOT null DEFAULT '0',
539
                            `timestamp` varchar(30) NOT null DEFAULT '0',
540
                            `user_language` varchar(50) NOT null DEFAULT '0',
541
                            `name` varchar(100) NULL,
542
                            `lastname` varchar(100) NULL,
543
                            `session_end` varchar(30) NULL,
544
                            `isAdministratedByRole` tinyint(5) NOT null DEFAULT '0',
545
                            `psk` varchar(400) NULL,
546
                            `ga` varchar(50) NULL,
547
                            `ga_temporary_code` VARCHAR(20) NOT NULL DEFAULT 'none',
548
                            `avatar` varchar(255) NULL,
549
                            `avatar_thumb` varchar(255) NULL,
550
                            `upgrade_needed` BOOLEAN NOT NULL DEFAULT FALSE,
551
                            `treeloadstrategy` varchar(30) NOT null DEFAULT 'full',
552
                            `can_manage_all_users` tinyint(1) NOT NULL DEFAULT '0',
553
                            `usertimezone` VARCHAR(50) NOT NULL DEFAULT 'not_defined',
554
                            `agses-usercardid` VARCHAR(50) NOT NULL DEFAULT '0',
555
                            `encrypted_psk` text NULL,
556
                            `user_ip` varchar(60) NOT null DEFAULT 'none',
557
                            PRIMARY KEY (`id`),
558
                            UNIQUE KEY `login` (`login`)
559
                            ) CHARSET=utf8;"
560
                        );
561
                    } elseif ($task === "tags") {
562
                        $mysqli_result = mysqli_query(
563
                            $dbTmp,
564
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."tags` (
565
                            `id` int(12) NOT null AUTO_INCREMENT,
566
                            `tag` varchar(30) NOT NULL,
567
                            `item_id` int(12) NOT NULL,
568
                            PRIMARY KEY (`id`),
569
                            UNIQUE KEY `id` (`id`)
570
                            ) CHARSET=utf8;"
571
                        );
572
                    } elseif ($task === "log_system") {
573
                        $mysqli_result = mysqli_query(
574
                            $dbTmp,
575
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."log_system` (
576
                            `id` int(12) NOT null AUTO_INCREMENT,
577
                            `type` varchar(20) NOT NULL,
578
                            `date` varchar(30) NOT NULL,
579
                            `label` text NOT NULL,
580
                            `qui` varchar(255) NOT NULL,
581
                            `field_1` varchar(250) DEFAULT NULL,
582
                            PRIMARY KEY (`id`)
583
                            ) CHARSET=utf8;"
584
                        );
585
                    } elseif ($task === "files") {
586
                        $mysqli_result = mysqli_query(
587
                            $dbTmp,
588
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."files` (
589
                            `id` int(11) NOT null AUTO_INCREMENT,
590
                            `id_item` int(11) NOT NULL,
591
                            `name` varchar(100) NOT NULL,
592
                            `size` int(10) NOT NULL,
593
                            `extension` varchar(10) NOT NULL,
594
                            `type` varchar(255) NOT NULL,
595
                            `file` varchar(50) NOT NULL,
596
                            `status` varchar(50) NOT NULL DEFAULT '0',
597
                            PRIMARY KEY (`id`)
598
                           ) CHARSET=utf8;"
599
                        );
600
                    } elseif ($task === "cache") {
601
                        $mysqli_result = mysqli_query(
602
                            $dbTmp,
603
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."cache` (
604
                            `id` int(12) NOT NULL,
605
                            `label` varchar(500) NOT NULL,
606
                            `description` text NOT NULL,
607
                            `tags` text DEFAULT NULL,
608
                            `id_tree` int(12) NOT NULL,
609
                            `perso` tinyint(1) NOT NULL,
610
                            `restricted_to` varchar(200) DEFAULT NULL,
611
                            `login` varchar(200) DEFAULT NULL,
612
                            `folder` varchar(300) NOT NULL,
613
                            `author` varchar(50) NOT NULL,
614
                            `renewal_period` tinyint(4) NOT NULL DEFAULT '0',
615
                            `timestamp` varchar(50) DEFAULT NULL,
616
                            `url` varchar(500) NOT NULL DEFAULT '0',
617
                            `encryption_type` VARCHAR(50) DEFAULT NULL DEFAULT '0'
618
                            ) CHARSET=utf8;"
619
                        );
620
                    } elseif ($task === "roles_title") {
621
                        $mysqli_result = mysqli_query(
622
                            $dbTmp,
623
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."roles_title` (
624
                            `id` int(12) NOT null AUTO_INCREMENT,
625
                            `title` varchar(50) NOT NULL,
626
                            `allow_pw_change` TINYINT(1) NOT null DEFAULT '0',
627
                            `complexity` INT(5) NOT null DEFAULT '0',
628
                            `creator_id` int(11) NOT null DEFAULT '0',
629
                            PRIMARY KEY (`id`)
630
                            ) CHARSET=utf8;"
631
                        );
632
                    } elseif ($task === "roles_values") {
633
                        $mysqli_result = mysqli_query(
634
                            $dbTmp,
635
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."roles_values` (
636
                            `role_id` int(12) NOT NULL,
637
                            `folder_id` int(12) NOT NULL,
638
                            `type` varchar(5) NOT NULL DEFAULT 'R',
639
                            KEY `role_id_idx` (`role_id`)
640
                            ) CHARSET=utf8;"
641
                        );
642
                    } elseif ($task === "kb") {
643
                        $mysqli_result = mysqli_query(
644
                            $dbTmp,
645
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb` (
646
                            `id` int(12) NOT null AUTO_INCREMENT,
647
                            `category_id` int(12) NOT NULL,
648
                            `label` varchar(200) NOT NULL,
649
                            `description` text NOT NULL,
650
                            `author_id` int(12) NOT NULL,
651
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
652
                            PRIMARY KEY (`id`)
653
                            ) CHARSET=utf8;"
654
                        );
655
                    } elseif ($task === "kb_categories") {
656
                        $mysqli_result = mysqli_query(
657
                            $dbTmp,
658
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb_categories` (
659
                            `id` int(12) NOT null AUTO_INCREMENT,
660
                            `category` varchar(50) NOT NULL,
661
                            PRIMARY KEY (`id`)
662
                            ) CHARSET=utf8;"
663
                        );
664
                    } elseif ($task === "kb_items") {
665
                        $mysqli_result = mysqli_query(
666
                            $dbTmp,
667
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb_items` (
668
                            `kb_id` int(12) NOT NULL,
669
                            `item_id` int(12) NOT NULL
670
                           ) CHARSET=utf8;"
671
                        );
672 View Code Duplication
                    } elseif ($task == "restriction_to_roles") {
673
                        $mysqli_result = mysqli_query(
674
                            $dbTmp,
675
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."restriction_to_roles` (
676
                            `role_id` int(12) NOT NULL,
677
                            `item_id` int(12) NOT NULL,
678
                            KEY `role_id_idx`  (`role_id`)
679
                            ) CHARSET=utf8;"
680
                        );
681
                    } elseif ($task === "languages") {
682
                        $mysqli_result = mysqli_query(
683
                            $dbTmp,
684
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."languages` (
685
                            `id` INT(10) NOT null AUTO_INCREMENT PRIMARY KEY ,
686
                            `name` VARCHAR(50) NOT null ,
687
                            `label` VARCHAR(50) NOT null ,
688
                            `code` VARCHAR(10) NOT null ,
689
                            `flag` VARCHAR(30) NOT NULL
690
                            ) CHARSET=utf8;"
691
                        );
692
693
                        // add lanaguages
694
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."languages` WHERE name = 'french'"));
695
                        if ($tmp[0] == 0) {
696
                            $mysql_result = mysqli_query(
697
                                $dbTmp,
698
                                "INSERT INTO `".$var['tbl_prefix']."languages` (`name`, `label`, `code`, `flag`) VALUES
699
                                ('french', 'French' , 'fr', 'fr.png'),
700
                                ('english', 'English' , 'us', 'us.png'),
701
                                ('spanish', 'Spanish' , 'es', 'es.png'),
702
                                ('german', 'German' , 'de', 'de.png'),
703
                                ('czech', 'Czech' , 'cz', 'cz.png'),
704
                                ('italian', 'Italian' , 'it', 'it.png'),
705
                                ('russian', 'Russian' , 'ru', 'ru.png'),
706
                                ('turkish', 'Turkish' , 'tr', 'tr.png'),
707
                                ('norwegian', 'Norwegian' , 'no', 'no.png'),
708
                                ('japanese', 'Japanese' , 'ja', 'ja.png'),
709
                                ('portuguese', 'Portuguese' , 'pr', 'pr.png'),
710
                                ('portuguese_br', 'Portuguese (Brazil)' , 'pr-bt', 'pr-bt.png'),
711
                                ('chinese', 'Chinese' , 'cn', 'cn.png'),
712
                                ('swedish', 'Swedish' , 'se', 'se.png'),
713
                                ('dutch', 'Dutch' , 'nl', 'nl.png'),
714
                                ('catalan', 'Catalan' , 'ct', 'ct.png'),
715
                                ('vietnamese', 'Vietnamese' , 'vi', 'vi.png'),
716
                                ('estonian', 'Estonian' , 'ee', 'ee.png');"
717
                            );
718
                        }
719
                    } elseif ($task === "emails") {
720
                        $mysqli_result = mysqli_query(
721
                            $dbTmp,
722
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."emails` (
723
                            `timestamp` INT(30) NOT null ,
724
                            `subject` VARCHAR(255) NOT null ,
725
                            `body` TEXT NOT null ,
726
                            `receivers` VARCHAR(255) NOT null ,
727
                            `status` VARCHAR(30) NOT NULL
728
                            ) CHARSET=utf8;"
729
                        );
730
                    } elseif ($task === "automatic_del") {
731
                        $mysqli_result = mysqli_query(
732
                            $dbTmp,
733
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."automatic_del` (
734
                            `item_id` int(11) NOT NULL,
735
                            `del_enabled` tinyint(1) NOT NULL,
736
                            `del_type` tinyint(1) NOT NULL,
737
                            `del_value` varchar(35) NOT NULL
738
                            ) CHARSET=utf8;"
739
                        );
740
                    } elseif ($task === "items_edition") {
741
                        $mysqli_result = mysqli_query(
742
                            $dbTmp,
743
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items_edition` (
744
                            `item_id` int(11) NOT NULL,
745
                            `user_id` int(12) NOT NULL,
746
                            `timestamp` varchar(50) NOT NULL
747
                            ) CHARSET=utf8;"
748
                        );
749
                    } elseif ($task === "categories") {
750
                        $mysqli_result = mysqli_query(
751
                            $dbTmp,
752
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories` (
753
                            `id` int(12) NOT NULL AUTO_INCREMENT,
754
                            `parent_id` int(12) NOT NULL,
755
                            `title` varchar(255) NOT NULL,
756
                            `level` int(2) NOT NULL,
757
                            `description` text NULL,
758
                            `type` varchar(50) NULL default '',
759
                            `order` int(12) NOT NULL default '0',
760
                            `encrypted_data` tinyint(1) NOT NULL default '1',
761
                            PRIMARY KEY (`id`)
762
                            ) CHARSET=utf8;"
763
                        );
764
                    } elseif ($task === "categories_items") {
765
                        $mysqli_result = mysqli_query(
766
                            $dbTmp,
767
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories_items` (
768
                            `id` int(12) NOT NULL AUTO_INCREMENT,
769
                            `field_id` int(11) NOT NULL,
770
                            `item_id` int(11) NOT NULL,
771
                            `data` text NOT NULL,
772
                            `data_iv` text NOT NULL,
773
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
774
                            PRIMARY KEY (`id`)
775
                            ) CHARSET=utf8;"
776
                        );
777
                    } elseif ($task === "categories_folders") {
778
                        $mysqli_result = mysqli_query(
779
                            $dbTmp,
780
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories_folders` (
781
                            `id_category` int(12) NOT NULL,
782
                            `id_folder` int(12) NOT NULL
783
                            ) CHARSET=utf8;"
784
                        );
785
                    } elseif ($task === "api") {
786
                        $mysqli_result = mysqli_query(
787
                            $dbTmp,
788
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."api` (
789
                            `id` int(20) NOT NULL AUTO_INCREMENT,
790
                            `type` varchar(15) NOT NULL,
791
                            `label` varchar(255) NOT NULL,
792
                            `value` varchar(255) NOT NULL,
793
                            `timestamp` varchar(50) NOT NULL,
794
                            PRIMARY KEY (`id`)
795
                            ) CHARSET=utf8;"
796
                        );
797
                    } elseif ($task === "otv") {
798
                        $mysqli_result = mysqli_query(
799
                            $dbTmp,
800
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."otv` (
801
                            `id` int(10) NOT NULL AUTO_INCREMENT,
802
                            `timestamp` text NOT NULL,
803
                            `code` varchar(100) NOT NULL,
804
                            `item_id` int(12) NOT NULL,
805
                            `originator` int(12) NOT NULL,
806
                            PRIMARY KEY (`id`)
807
                            ) CHARSET=utf8;"
808
                        );
809
                    } elseif ($task === "suggestion") {
810
                        $mysqli_result = mysqli_query(
811
                            $dbTmp,
812
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."suggestion` (
813
                            `id` tinyint(12) NOT NULL AUTO_INCREMENT,
814
                            `label` varchar(255) NOT NULL,
815
                            `pw` text NOT NULL,
816
                            `pw_iv` text NOT NULL,
817
                            `pw_len` int(5) NOT NULL,
818
                            `description` text NOT NULL,
819
                            `author_id` int(12) NOT NULL,
820
                            `folder_id` int(12) NOT NULL,
821
                            `comment` text NOT NULL,
822
                            `suggestion_type` varchar(10) NOT NULL default 'new',
823
                            PRIMARY KEY (`id`)
824
                            ) CHARSET=utf8;"
825
                        );
826
827
                        $mysqli_result = mysqli_query(
828
                            $dbTmp,
829
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."export` (
830
                            `id` int(12) NOT NULL,
831
                            `label` varchar(255) NOT NULL,
832
                            `login` varchar(100) NOT NULL,
833
                            `description` text NOT NULL,
834
                            `pw` text NOT NULL,
835
                            `path` varchar(500) NOT NULL,
836
                            `email` varchar(500) NOT NULL default 'none',
837
                            `url` varchar(500) NOT NULL default 'none',
838
                            `kbs` varchar(500) NOT NULL default 'none',
839
                            `tags` varchar(500) NOT NULL default 'none'
840
                            ) CHARSET=utf8;"
841
                        );
842
                    } elseif ($task === "tokens") {
843
                        $mysqli_result = mysqli_query(
844
                            $dbTmp,
845
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."tokens` (
846
                            `id` int(12) NOT NULL AUTO_INCREMENT,
847
                            `user_id` int(12) NOT NULL,
848
                            `token` varchar(255) NOT NULL,
849
                            `reason` varchar(255) NOT NULL,
850
                            `creation_timestamp` varchar(50) NOT NULL,
851
                            `end_timestamp` varchar(50) NOT NULL,
852
                            PRIMARY KEY (`id`)
853
                            ) CHARSET=utf8;"
854
                        );
855
                    } elseif ($task === "items_change") {
856
                        $mysqli_result = mysqli_query(
857
                            $dbTmp,
858
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items_change` (
859
                            `id` int(12) NOT NULL AUTO_INCREMENT,
860
                            `item_id` int(12) NOT NULL,
861
                            `label` varchar(255) NOT NULL DEFAULT 'none',
862
                            `pw` text NOT NULL,
863
                            `login` varchar(255) NOT NULL DEFAULT 'none',
864
                            `email` varchar(255) NOT NULL DEFAULT 'none',
865
                            `url` varchar(255) NOT NULL DEFAULT 'none',
866
                            `description` text NOT NULL,
867
                            `comment` text NOT NULL,
868
                            `folder_id` tinyint(12) NOT NULL,
869
                            `user_id` int(12) NOT NULL,
870
                            `timestamp` varchar(50) NOT NULL DEFAULT 'none',
871
                            PRIMARY KEY (`id`)
872
                            ) CHARSET=utf8;"
873
                        );
874
                    }
875
                } elseif ($activity === "populate") {
876
                    // include constants
877
                    require_once "../includes/config/include.php";
878
879
                    if ($task === "admin") {
880
                        // check that admin accounts doesn't exist
881
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE login = 'admin'"));
882
                        if ($tmp == 0) {
883
                            $mysqli_result = mysqli_query(
884
                                $dbTmp,
885
                                "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `admin`, `gestionnaire`, `personal_folder`, `groupes_visibles`, `email`, `encrypted_psk`, `last_pw_change`) VALUES ('1', 'admin', '".bCrypt($var['admin_pwd'], '13')."', '1', '0', '0', '', '', '', '".time()."')"
886
                            );
887
                        } else {
888
                            $mysqli_result = mysqli_query($dbTmp, "UPDATE `".$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'], '13')."' WHERE login = 'admin' AND id = '1'");
889
                        }
890
891
                        // check that API doesn't exist
892
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE id = '".API_USER_ID."'"));
893 View Code Duplication
                        if ($tmp == 0) {
894
                            $mysqli_result = mysqli_query(
895
                                $dbTmp,
896
                                "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES ('".API_USER_ID."', 'API', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')"
897
                            );
898
                        }
899
900
                        // check that OTV doesn't exist
901
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE id = '".OTV_USER_ID."'"));
902 View Code Duplication
                        if ($tmp == 0) {
903
                            $mysqli_result = mysqli_query(
904
                                $dbTmp,
905
                                "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES ('".OTV_USER_ID."', 'OTV', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')"
906
                            );
907
                        }
908
                    }
909
                }
910
                // answer back
911
                if ($mysqli_result) {
912
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'", "task" : "'.$task.'", "activity" : "'.$activity.'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"... "' . $activity . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 912

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
913
                } else {
914
                    echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_error())).'", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'", "table" : "'.$task.'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "' . addsla...e" : "' . $task . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 914

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
915
                }
916 View Code Duplication
            } else {
917
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
918
            }
919
920
            mysqli_close($dbTmp);
921
            // Destroy session without writing to disk
922
            define('NODESTROY_SESSION', 'true');
923
            session_destroy();
924
            break;
925
926
        case "step_6":
927
            //decrypt
928
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
929
            $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
930
            $data_sent = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
931
            $data_sent = json_decode($data_sent, true);
932
            $task = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
933
            $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
934
            $db = json_decode($json, true);
935
936
            $dbTmp = mysqli_connect(
937
                $db['db_host'],
938
                $db['db_login'],
939
                $db['db_pw'],
940
                $db['db_bdd'],
941
                $db['db_port']
942
            );
943
944
            // read install variables
945
            $result = mysqli_query($dbTmp, "SELECT * FROM `_install`");
946
            while ($row = $result->fetch_array()) {
947
                $var[$row[0]] = $row[1];
948
            }
949
950
            // launch
951
            if (empty($var['sk_path'])) {
952
                $skFile = $var['abspath'].'/includes/sk.php';
953
                $securePath = $var['abspath'];
954
            } else {
955
                //ensure $var['sk_path'] has no trailing slash
956
                $var['sk_path'] = rtrim($var['sk_path'], '/\\');
957
                $skFile = $var['sk_path'].'/sk.php';
958
                $securePath = $var['sk_path'];
959
            }
960
961
            $events = "";
962
963
            if ($activity === "file") {
964
                if ($task === "settings.php") {
965
                    $filename = "../includes/config/settings.php";
966
967
                    if (file_exists($filename)) {
968
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
969
                            echo '[{"error" : "Setting.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "Setting.ph...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 969

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
970
                            break;
971
                        } else {
972
                            $events .= "The file $filename already exist. A copy has been created.<br />";
973
                            unlink($filename);
974
                        }
975
                    }
976
                    $fh = fopen($filename, 'w');
977
978
                    $result = fwrite(
979
                        $fh,
980
                        utf8_encode(
981
                            "<?php
982
global \$lang, \$txt, \$k, \$pathTeampas, \$urlTeampass, \$pwComplexity, \$mngPages;
983
global \$server, \$user, \$pass, \$database, \$pre, \$db, \$port, \$encoding;
984
985
### DATABASE connexion parameters ###
986
\$server = \"".$db['db_host']."\";
987
\$user = \"".$db['db_login']."\";
988
\$pass = \"".str_replace("$", "\\$", $db['db_pw'])."\";
989
\$database = \"".$db['db_bdd']."\";
990
\$pre = \"".$var['tbl_prefix']."\";
991
\$port = ".$db['db_port'].";
992
\$encoding = \"".$_SESSION['db_encoding']."\";
993
994
@date_default_timezone_set(\$_SESSION['settings']['timezone']);
995
@define('SECUREPATH', '".$securePath."');
996
if (file_exists(\"".str_replace('\\', '/', $skFile)."\")) {
997
    require_once \"".str_replace('\\', '/', $skFile)."\";
998
}
999
?>"
1000
                        )
1001
                    );
1002
                    fclose($fh);
1003 View Code Duplication
                    if ($result === false) {
1004
                        echo '[{"error" : "Setting.php file could not be created. Please check the path and the rights", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "Setting.ph...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1004

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1005
                    } else {
1006
                        echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1006

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1007
                    }
1008
                } elseif ($task === "sk.php") {
1009
//Create sk.php file
1010 View Code Duplication
                    if (file_exists($skFile)) {
1011
                        if (!copy($skFile, $skFile.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1012
                            echo '[{"error" : "sk.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "sk.php fil...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1012

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1013
                            break;
1014
                        } else {
1015
                            unlink($skFile);
1016
                        }
1017
                    }
1018
                    $fh = fopen($skFile, 'w');
1019
1020
                    $result = fwrite(
1021
                        $fh,
1022
                        utf8_encode(
1023
                            "<?php
1024
@define('COST', '13'); // Don't change this.
1025
@define('AKEY', '');
1026
@define('IKEY', '');
1027
@define('SKEY', '');
1028
@define('HOST', '');
1029
?>"
1030
                        )
1031
                    );
1032
                    fclose($fh);
1033
1034
                    // finalize
1035 View Code Duplication
                    if ($result === false) {
1036
                        echo '[{"error" : "sk.php file could not be created. Please check the path and the rights.", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "sk.php fil...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1036

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1037
                    } else {
1038
                        echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1038

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1039
                    }
1040
                } elseif ($task === "security") {
1041
                    # Sort out the file permissions
1042
1043
                    // is server Windows or Linux?
1044
                    if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
1045
                        // Change directory permissions
1046
                        $result = chmod_r($_SESSION['abspath'], 0770, 0740);
1047
                        if ($result) {
1048
                            $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770);
1049
                        }
1050
                        if ($result) {
1051
                            $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770);
1052
                        }
1053
                    }
1054
1055 View Code Duplication
                    if ($result === false) {
1056
                        echo '[{"error" : "Cannot change directory permissions - please fix manually", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "Cannot cha...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1056

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1057
                    } else {
1058
                        echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1058

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1059
                    }
1060
                } elseif ($task === "teampass-seckey") {
1061
                    // create teampass-seckey.txt
1062
                    require_once '../includes/libraries/Encryption/Encryption/Crypto.php';
1063
                    require_once '../includes/libraries/Encryption/Encryption/Encoding.php';
1064
                    require_once '../includes/libraries/Encryption/Encryption/DerivedKeys.php';
1065
                    require_once '../includes/libraries/Encryption/Encryption/Key.php';
1066
                    require_once '../includes/libraries/Encryption/Encryption/KeyOrPassword.php';
1067
                    require_once '../includes/libraries/Encryption/Encryption/File.php';
1068
                    require_once '../includes/libraries/Encryption/Encryption/RuntimeTests.php';
1069
                    require_once '../includes/libraries/Encryption/Encryption/KeyProtectedByPassword.php';
1070
                    require_once '../includes/libraries/Encryption/Encryption/Core.php';
1071
1072
                    $key = \Defuse\Crypto\Key::createNewRandomKey();
1073
                    $new_salt = $key->saveToAsciiSafeString();
1074
1075
                    file_put_contents(
1076
                        $securePath."/teampass-seckey.txt",
1077
                        $new_salt
1078
                    );
1079
1080
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1080

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1081
                } elseif ($task === "csrfp-token") {
1082
                    // update CSRFP TOKEN
1083
                    $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
1084
                    $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
1085
                    if (file_exists($csrfp_file)) {
1086
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1087
                            echo '[{"error" : "csrfp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "csrfp.conf...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1087

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1088
                            break;
1089
                        } else {
1090
                            $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
1091
                        }
1092
                    }
1093
                    unlink($csrfp_file); // delete existing csrfp.config file
1094
                    copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
1095
                    $data = file_get_contents($csrfp_file);
1096
                    $newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "'.bin2hex(openssl_random_pseudo_bytes(25)).'"', $data);
1097
                    $jsUrl = $data_sent['url_path'].'/includes/libraries/csrfp/js/csrfprotector.js';
1098
                    $newdata = str_replace('"jsUrl" => ""', '"jsUrl" => "'.$jsUrl.'"', $newdata);
1099
                    file_put_contents("../includes/libraries/csrfp/libs/csrfp.config.php", $newdata);
1100
1101
                    echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1101

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1102
                }
1103
            }
1104
1105
            mysqli_close($dbTmp);
1106
            // Destroy session without writing to disk
1107
            define('NODESTROY_SESSION', 'true');
1108
            session_destroy();
1109
            break;
1110
1111
        case "step_7":
1112
            // Decrypt
1113
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
1114
            $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
1115
            $task = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
1116
            $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

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...
1117
            $db = json_decode($json, true);
1118
            // launch
1119
            $dbTmp = @mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
1120
1121
            if ($activity === "file") {
1122
                if ($task === "deleteInstall") {
1123
                    function delTree($dir)
1124
                    {
1125
                        $files = array_diff(scandir($dir), array('.', '..'));
1126
1127
                        foreach ($files as $file) {
1128
                            (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
1129
                        }
1130
                        return rmdir($dir);
1131
                    }
1132
1133
                    $result = true;
1134
                    $errorMsg = "Cannot delete `install` folder. Please do it manually.";
1135
                    if (file_exists($_SESSION['abspath'].'/install')) {
1136
                        // set the permissions on the install directory and delete
1137
                        // is server Windows or Linux?
1138
                        if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
1139
                            chmod_r($_SESSION['abspath'].'/install', 0755, 0440);
1140
                        }
1141
                        $result = delTree($_SESSION['abspath'].'/install');
1142
                    }
1143
1144
                    // delete temporary install table
1145
                    $result = mysqli_query($dbTmp, "DROP TABLE `_install`");
1146
                    $errorMsg = "Cannot remove `_install` table. Please do it manually.";
1147
1148 View Code Duplication
                    if ($result === false) {
1149
                        echo '[{"error" : "'.$errorMsg.'", "index" : "'.$_POST['index'].'", "result" : "", "multiple" : ""}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "' . $error... "", "multiple" : ""}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1149

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1150
                    } else {
1151
                        echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]';
0 ignored issues
show
Security Cross-Site Scripting introduced by
'[{"error" : "", "index"...OST['multiple'] . '"}]' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_POST
    in install/install.queries.php on line 1151

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1152
                    }
1153
                }
1154
            }
1155
            // delete install table
1156
            //
1157
            mysqli_close($dbTmp);
1158
            // Destroy session without writing to disk
1159
            define('NODESTROY_SESSION', 'true');
1160
            session_destroy();
1161
            break;
1162
    }
1163
}
1164