mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 00:02:17 +02:00
N°6238 Security hardening
This commit is contained in:
@@ -23,9 +23,9 @@ final class Utils
|
||||
{
|
||||
switch (\gettype($input)) {
|
||||
case 'object':
|
||||
return 'object(' . \get_class($input) . ')';
|
||||
return 'object('.\get_class($input).')';
|
||||
case 'array':
|
||||
return 'array(' . \count($input) . ')';
|
||||
return 'array('.\count($input).')';
|
||||
default:
|
||||
\ob_start();
|
||||
\var_dump($input);
|
||||
@@ -79,19 +79,22 @@ final class Utils
|
||||
*
|
||||
* The returned handler is not wrapped by any default middlewares.
|
||||
*
|
||||
* @throws \RuntimeException if no viable Handler is available.
|
||||
*
|
||||
* @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system.
|
||||
*
|
||||
* @throws \RuntimeException if no viable Handler is available.
|
||||
*/
|
||||
public static function chooseHandler(): callable
|
||||
{
|
||||
$handler = null;
|
||||
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
|
||||
$handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler());
|
||||
} elseif (\function_exists('curl_exec')) {
|
||||
$handler = new CurlHandler();
|
||||
} elseif (\function_exists('curl_multi_exec')) {
|
||||
$handler = new CurlMultiHandler();
|
||||
|
||||
if (\defined('CURLOPT_CUSTOMREQUEST')) {
|
||||
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
|
||||
$handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler());
|
||||
} elseif (\function_exists('curl_exec')) {
|
||||
$handler = new CurlHandler();
|
||||
} elseif (\function_exists('curl_multi_exec')) {
|
||||
$handler = new CurlMultiHandler();
|
||||
}
|
||||
}
|
||||
|
||||
if (\ini_get('allow_url_fopen')) {
|
||||
@@ -244,8 +247,8 @@ EOT
|
||||
}
|
||||
// Special match if the area when prefixed with ".". Remove any
|
||||
// existing leading "." and add a new leading ".".
|
||||
$area = '.' . \ltrim($area, '.');
|
||||
if (\substr($host, -(\strlen($area))) === $area) {
|
||||
$area = '.'.\ltrim($area, '.');
|
||||
if (\substr($host, -\strlen($area)) === $area) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -266,13 +269,13 @@ EOT
|
||||
*
|
||||
* @throws InvalidArgumentException if the JSON cannot be decoded.
|
||||
*
|
||||
* @link https://www.php.net/manual/en/function.json-decode.php
|
||||
* @see https://www.php.net/manual/en/function.json-decode.php
|
||||
*/
|
||||
public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0)
|
||||
{
|
||||
$data = \json_decode($json, $assoc, $depth, $options);
|
||||
if (\JSON_ERROR_NONE !== \json_last_error()) {
|
||||
throw new InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
|
||||
throw new InvalidArgumentException('json_decode error: '.\json_last_error_msg());
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -287,13 +290,13 @@ EOT
|
||||
*
|
||||
* @throws InvalidArgumentException if the JSON cannot be encoded.
|
||||
*
|
||||
* @link https://www.php.net/manual/en/function.json-encode.php
|
||||
* @see https://www.php.net/manual/en/function.json-encode.php
|
||||
*/
|
||||
public static function jsonEncode($value, int $options = 0, int $depth = 512): string
|
||||
{
|
||||
$json = \json_encode($value, $options, $depth);
|
||||
if (\JSON_ERROR_NONE !== \json_last_error()) {
|
||||
throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
|
||||
throw new InvalidArgumentException('json_encode error: '.\json_last_error_msg());
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
@@ -338,7 +341,7 @@ EOT
|
||||
|
||||
$errorMessage = 'IDN conversion failed';
|
||||
if ($errors) {
|
||||
$errorMessage .= ' (errors: ' . implode(', ', $errors) . ')';
|
||||
$errorMessage .= ' (errors: '.implode(', ', $errors).')';
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException($errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user