Issues (8)

Security Analysis    no vulnerabilities found

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/OrtcClient.php (6 issues)

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 ninjacto\OrtcPhp;
4
5
use GuzzleHttp\Exception\ClientException;
6
use GuzzleHttp\Message\FutureResponse;
7
use GuzzleHttp\Pool;
8
use ninjacto\OrtcPhp\Exceptions\BatchRequestException;
9
use ninjacto\OrtcPhp\Exceptions\InvalidBalancerUrlException;
10
use ninjacto\OrtcPhp\Exceptions\NetworkErrorException;
11
use ninjacto\OrtcPhp\Exceptions\UnauthorizedException;
12
use ninjacto\OrtcPhp\Models\Requests\OrtcRequest;
13
14
class OrtcClient
15
{
16
    /**
17
     * @var \GuzzleHttp\Client
18
     */
19
    protected $guzzleClient;
20
21
    /**
22
     * @var OrtcRequest
23
     */
24
    protected $request;
25
26
    /**
27
     * @var string
28
     */
29
    protected $baseUrl;
30
31
    /**
32
     * execute single request.
33
     *
34
     * @throws UnauthorizedException
35
     * @throws NetworkErrorException
36
     * @throws InvalidBalancerUrlException
37
     *
38
     * @return Models\Responses\OrtcResponse
39
     */
40
    public function execute()
41
    {
42
        $response = null;
43
44
        try {
45
            $guzzleRequest = $this->createRequest();
46
47
            /** @var FutureResponse $response */
48
            $response = $this->guzzleClient->send($guzzleRequest);
49
        } catch (ClientException $e) {
50
            if ($e->getResponse()->getStatusCode() == 401) {
51
                throw new UnauthorizedException();
52
            } else {
53
                $networkErrorException = new NetworkErrorException();
54
                $networkErrorException->setGuzzleClientException($e);
55
56
                throw $networkErrorException;
57
            }
58
        }
59
60
        $handler = $this->request->getResponseHandler();
61
62
        return $handler->handle($response);
63
    }
64
65
    /**
66
     * execute batch requests (post).
67
     *
68
     * @throws BatchRequestException
69
     *
70
     * @return Models\Responses\OrtcResponse
71
     */
72
    public function batchExecute()
73
    {
74
        $guzzleRequests = $this->createBatchPostRequests();
75
76
        $results = Pool::batch($this->guzzleClient, $guzzleRequests, [
77
            'pool_size' => $this->request->getOrtcConfig()->getBatchPoolSize(),
78
        ]);
79
80
        if (count($results->getFailures()) > 0) {
0 ignored issues
show
The method getFailures cannot be called on $results (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
81
            $batchRequestException = new BatchRequestException();
82
            $batchRequestException->setResults($results);
0 ignored issues
show
$results is of type array, but the function expects a object<GuzzleHttp\BatchResults>.

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
84
            throw $batchRequestException;
85
        }
86
87
        $handler = $this->request->getResponseHandler();
88
89
        return $handler->handle($results);
0 ignored issues
show
$results is of type array, but the function expects a object<GuzzleHttp\Messag...uzzleHttp\BatchResults>.

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...
90
    }
91
92
    /**
93
     * @param \GuzzleHttp\Client $guzzleClient
94
     */
95
    public function setGuzzleClient($guzzleClient)
96
    {
97
        $this->guzzleClient = $guzzleClient;
98
    }
99
100
    /**
101
     * @param OrtcRequest $request
102
     */
103
    public function setRequest($request)
104
    {
105
        $this->request = $request;
106
    }
107
108
    /**
109
     * @param string $baseUrl
110
     */
111
    public function setBaseUrl($baseUrl)
112
    {
113
        $this->baseUrl = $baseUrl;
114
    }
115
116
    /**
117
     * get request options for post requests.
118
     *
119
     * @param array $postData
120
     *
121
     * @return array
122
     */
123
    protected function getRequestOptionsForPost($postData)
124
    {
125
        return [
126
            'verify' => $this->request->getOrtcConfig()->isVerifySsl(),
127
            'body'   => $postData,
128
        ];
129
    }
130
131
    /**
132
     * get request options for get requests.
133
     *
134
     * @return array
135
     */
136
    protected function getRequestOptionsForGet()
137
    {
138
        return [
139
            'verify' => $this->request->getOrtcConfig()->isVerifySsl(),
140
        ];
141
    }
142
143
    /**
144
     * create guzzle GET/POST request.
145
     *
146
     * @return \Psr\Http\Message\RequestInterface
147
     */
148
    protected function createRequest()
149
    {
150
        if ($this->request->isPost()) {
151
            return $this->guzzleClient->createRequest(
0 ignored issues
show
The method createRequest() does not exist on GuzzleHttp\Client. Did you maybe mean request()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
152
                'POST',
153
                $this->getRequestUrl(),
154
                $this->getRequestOptionsForPost($this->request->getPostData())
155
            );
156
        } else {
157
            return $this->guzzleClient->createRequest(
0 ignored issues
show
The method createRequest() does not exist on GuzzleHttp\Client. Did you maybe mean request()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
158
                'GET',
159
                $this->getRequestUrl(),
160
                $this->getRequestOptionsForGet()
161
            );
162
        }
163
    }
164
165
    /**
166
     * create batch guzzle POST requests.
167
     *
168
     * @return \GuzzleHttp\Message\Request[]
169
     */
170
    protected function createBatchPostRequests()
171
    {
172
        $requests = [];
173
174
        foreach ($this->request->getPostData() as $postData) {
175
            $requests[] = $this->guzzleClient->createRequest(
0 ignored issues
show
The method createRequest() does not exist on GuzzleHttp\Client. Did you maybe mean request()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
176
                'POST',
177
                $this->getRequestUrl(),
178
                $this->getRequestOptionsForPost($postData)
179
            );
180
        }
181
182
        return $requests;
183
    }
184
185
    /**
186
     * combine path url & baseUrl if needed!
187
     */
188
    protected function getRequestUrl()
189
    {
190
        if (!$this->request->isUrlAbsolute()) {
191
            return $this->baseUrl . $this->request->getUrlPath();
192
        } else {
193
            return $this->request->getUrlPath();
194
        }
195
    }
196
}
197