Issues (493)

lib/SP/Util/HttpUtil.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Util;
26
27
use SP\Config\ConfigData;
28
use SP\Html\Html;
29
use SP\Http\Request;
30
31
/**
32
 * Class HttpUtil
33
 *
34
 * @package SP\Util
35
 */
36
final class HttpUtil
37
{
38
    /**
39
     * Comprobar y forzar (si es necesario) la conexión HTTPS
40
     *
41
     * @param ConfigData $configData
42
     * @param Request    $request
43
     */
44
    public static function checkHttps(ConfigData $configData, Request $request)
45
    {
46
        if ($configData->isHttpsEnabled() && !$request->isHttps()) {
47
            $serverPort = $request->getServerPort();
48
49
            $port = $serverPort !== 443 ? ':' . $serverPort : '';
50
            $host = str_replace('http', 'https', $request->getHttpHost());
51
52
            header('Location: ' . $host . $port . $_SERVER['REQUEST_URI']);
53
        }
54
    }
55
56
    /**
57
     * Comprobar si existen parámetros pasados por POST para enviarlos por GET
58
     */
59
    public static function importUrlParamsToGet()
60
    {
61
        $params = [];
62
63
        foreach ($_REQUEST as $param => $value) {
64
            $param = Filter::getString($param);
65
66
            if (strpos($param, 'g_') !== false) {
67
                $params[] = substr($param, 2) . '=' . Html::sanitize($value);
0 ignored issues
show
Are you sure SP\Html\Html::sanitize($value) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
                $params[] = substr($param, 2) . '=' . /** @scrutinizer ignore-type */ Html::sanitize($value);
Loading history...
68
            }
69
        }
70
71
        return count($params) > 0 ? '?' . implode('&', $params) : '';
72
    }
73
}