Issues (1)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/JCRequest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 31/05/2017
6
 * Time: 09:40
7
 */
8
9
namespace JC\HttpClient;
10
11
12
use GuzzleHttp\Client;
13
use GuzzleHttp\Exception\RequestException;
14
use JC\HttpClient\Enums\Method;
15
use Purl\Url;
16
17
class JCRequest implements JCRequestInterface
18 7
{
19
    public static function request($method, $url, $clientOptions)
20 7
    {
21
        try {
22
            return new JCResponse((new Client())->request($method, $url, static::combineParams($clientOptions)));
23 1
        } catch (RequestException $exception) {
24
            return new JCResponse($exception->getResponse());
25 1
        }
26
    }
27 1
28
    public static function get($url, $params = null, $headers = [], $options = [])
29
    {
30 2
        return static::request(Method::GET, is_array($params) ? static::combineUrl($url, $params) : $url,
31
            array_merge(['headers' => $headers], $options));
32 2
    }
33 2
34
    public static function post($url, $params = null, $headers = [], $options = [])
35 2
    {
36
        return static::request(Method::POST, $url,
37
            array_merge(['headers' => $headers, 'params' => $params], $options));
38 1
    }
39
40 1
    public static function put($url, $params = null, $headers = [], $options = [])
41 1
    {
42
        return static::request(Method::PUT, $url,
43 1
            array_merge(['headers' => $headers, 'params' => $params], $options));
44
    }
45
46 1
    public static function patch($url, $params = null, $headers = [], $options = [])
47
    {
48 1
        return static::request(Method::PATCH, $url,
49 1
            array_merge(['headers' => $headers, 'params' => $params], $options));
50
    }
51 1
52
    public static function delete($url, $params = null, $headers = [], $options = [])
53
    {
54 1
        return static::request(Method::DELETE, $url,
55
            array_merge(['headers' => $headers, 'params' => $params], $options));
56 1
    }
57 1
58
    public static function head($url, $headers = [], $options = [])
59 1
    {
60
        return static::request(Method::HEAD, $url,
61
            array_merge(['headers' => $headers], $options));
62 2
    }
63
64 1
    /**
65 2
     * Manipulate the url & params for GET request
66 1
     *
67
     * @param string $url
68
     * @param array $params
69
     * @return string
70
     */
71
    protected static function combineUrl($url, $params = [])
72
    {
73
        $urlObject = Url::parse($url);
74
        $queryData = array_merge($urlObject->query->getData(), $params);
75
        $urlObject->query->setData($queryData);
76 1
77
        return $urlObject->getUrl();
78 1
    }
79 1
80 1
    /**
81
     * @param array $guzzleOptions
82 1
     * @return array
83
     */
84
    protected static function combineParams($guzzleOptions)
85
    {
86
        if (isset($guzzleOptions['params'])) {
87
            $params = $guzzleOptions['params'];
88
            unset($guzzleOptions['params']);
89 7
90
            if (is_array($params)) {
91 7
                $guzzleOptions['form_params'] = $params;
92 5
            } elseif (is_string($params) && $jsonObject = static::jsonDecode($params)) {
0 ignored issues
show
Since jsonDecode() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of jsonDecode() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
93 5
                $guzzleOptions['json'] = $jsonObject;
94
            } else {
95 5
                $guzzleOptions['body'] = $params;
96 4
            }
97 4
        }
98 1
99 1
        return $guzzleOptions;
100 1
    }
101 1
102
    /**
103
     * @param $string
104
     * @return bool|mixed
105 5
     */
106
    private static function jsonDecode($string)
107 7
    {
108
        $jsonObject = json_decode($string);
109
        if (json_last_error() == JSON_ERROR_NONE) {
110
            return $jsonObject;
111
        } else {
112
            return false;
113
        }
114
    }
115
}