Issues (100)

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/Kernel/BaseClient.php (2 issues)

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
namespace Kaylyu\Alipay\Kernel;
4
5
use Kaylyu\Alipay\Kernel\Http\Response;
6
use Kaylyu\Alipay\Kernel\Traits\HasHttpRequests;
7
use GuzzleHttp\MessageFormatter;
8
use GuzzleHttp\Middleware;
9
10
/**
11
 * Class BaseClient.
12
 */
13
class BaseClient
14
{
15
    use HasHttpRequests {
16
        request as performRequest;
17
    }
18
19
    /**
20
     * @var \Kaylyu\Alipay\Kernel\ServiceContainer
21
     */
22
    protected $app;
23
24
    /**
25
     * @var
26
     */
27
    protected $baseUri;
28
29
    /**
30
     * BaseClient constructor.
31
     *
32
     * @param \Kaylyu\Alipay\Kernel\ServiceContainer $app
33
     */
34
    public function __construct(ServiceContainer $app)
35
    {
36
        $this->app = $app;
37
    }
38
39
    /**
40
     * GET request.
41
     *
42
     * @param string $url
43
     * @param array $query
44
     * @param array $forceArrayKeys
45
     *
46
     * @return \Psr\Http\Message\ResponseInterface|\Kaylyu\Alipay\Kernel\Support\Collection|array|object|string
47
     *
48
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
49
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
50
     */
51
    public function httpGet(string $url, array $query = [], array $forceArrayKeys = [])
52
    {
53
        return $this->request($url, 'GET', ['query' => $query],false, $forceArrayKeys);
54
    }
55
56
    /**
57
     * POST request.
58
     *
59
     * @param string $url
60
     * @param array $data
61
     * @param array $forceArrayKeys
62
     *
63
     * @return \Psr\Http\Message\ResponseInterface|\Kaylyu\Alipay\Kernel\Support\Collection|array|object|string
64
     *
65
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
66
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
67
     */
68
    public function httpPost(string $url, array $data = [], array $forceArrayKeys = [])
69
    {
70
        return $this->request($url, 'POST', ['form_params' => $data],false, $forceArrayKeys);
71
    }
72
73
    /**
74
     * JSON request.
75
     *
76
     * @param string $url
77
     * @param array $data
78
     * @param array $forceArrayKeys
79
     *
80
     * @return \Psr\Http\Message\ResponseInterface|\Kaylyu\Alipay\Kernel\Support\Collection|array|object|string
81
     *
82
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
83
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
84
     */
85
    public function httpPostJson(string $url, array $data = [], array $forceArrayKeys = [])
86
    {
87
        return $this->request($url, 'POST', ['json' => $data], false, $forceArrayKeys );
88
    }
89
90
    /**
91
     * Upload file.
92
     *
93
     * @param string $url
94
     * @param array $files
95
     * @param array $form
96
     * @param array $query
97
     *
98
     * @return \Psr\Http\Message\ResponseInterface|\Kaylyu\Alipay\Kernel\Support\Collection|array|object|string
99
     *
100
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
101
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
102
     */
103
    public function httpUpload(string $url, array $files = [], array $form = [], array $query = [])
104
    {
105
        $multipart = [];
106
107
        foreach ($files as $name => $path) {
108
            $multipart[] = [
109
                'name' => $name,
110
                'contents' => fopen($path, 'r'),
111
            ];
112
        }
113
114
        foreach ($form as $name => $contents) {
115
            $multipart[] = compact('name', 'contents');
116
        }
117
118
        return $this->request($url, 'POST', [
119
            'query' => $query,
120
            'multipart' => $multipart,
121
            'connect_timeout' => 30,
122
            'timeout' => 30,
123
            'read_timeout' => 30
124
        ]);
125
    }
126
127
    /**
128
     * @param string $url
129
     * @param string $method
130
     * @param array $options
131
     * @param bool $returnRaw
132
     * @param array $forceArrayKeys
133
     *
134
     * @return \Psr\Http\Message\ResponseInterface|\Kaylyu\Alipay\Kernel\Support\Collection|array|object|string
135
     *
136
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
137
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
138
     */
139
    public function request(string $url, string $method = 'GET', array $options = [], $returnRaw = false, array $forceArrayKeys = [])
140
    {
141
        if (empty($this->middlewares)) {
142
            $this->registerHttpMiddlewares();
143
        }
144
145
        $response = $this->performRequest($url, $method, $options);
146
147
        return $returnRaw ? $response
148
            : $this->castResponseToType($response, $this->app->config->get('response_type'), $forceArrayKeys);
0 ignored issues
show
$response is of type array|object|string, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
149
    }
150
151
    /**
152
     * @param string $url
153
     * @param string $method
154
     * @param array $options
155
     *
156
     * @return \Kaylyu\Alipay\Kernel\Http\Response
157
     *
158
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\InvalidConfigException
159
     * @throws \Kaylyu\Alipay\Kernel\Exceptions\Exception
160
     */
161
    public function requestRaw(string $url, string $method = 'GET', array $options = [])
162
    {
163
        return Response::buildFromPsrResponse($this->request($url, $method, $options, true));
0 ignored issues
show
$this->request($url, $method, $options, true) is of type array|object|string, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
164
    }
165
166
    /**
167
     * Register Guzzle middlewares.
168
     */
169
    protected function registerHttpMiddlewares()
170
    {
171
        // log
172
        $this->pushMiddleware($this->logMiddleware(), 'log');
173
    }
174
175
    /**
176
     * Log the request.
177
     *
178
     * @return \Closure
179
     */
180
    protected function logMiddleware()
181
    {
182
        $formatter = new MessageFormatter($this->app['config']['http.log_template'] ?? MessageFormatter::DEBUG);
183
184
        return Middleware::log($this->app['logger'], $formatter);
185
    }
186
}
187