Issues (9)

Security Analysis    no request data  

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/GuzzleAdapter.php (2 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 DominionEnterprises\Api;
4
5
use ArrayObject;
6
use DominionEnterprises\Util;
7
use GuzzleHttp\Client as GuzzleClient;
8
use GuzzleHttp\Exception\RequestException;
9
use GuzzleHttp\Promise;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * Concrete implentation of Adapter interface
14
 */
15
final class GuzzleAdapter implements Adapter
16
{
17
    /**
18
     * Collection of Promise\PromiseInterface instances with keys matching what was given from start().
19
     *
20
     * @var array
21
     */
22
    private $_promises = [];
23
24
    /**
25
     * Collection of Api\Response with keys matching what was given from start().
26
     *
27
     * @var array
28
     */
29
    private $_responses = [];
30
31
    /**
32
     * Collection of \Exception with keys matching what was given from start().
33
     *
34
     * @var array
35
     */
36
    private $_exceptions = [];
37
38
    /**
39
     * @var \Guzzle\Http\Client
40
     */
41
    private $_client;
42
43
    public function __construct()
44
    {
45
        $this->_client = new GuzzleClient(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \GuzzleHttp\Client(a...http_errors' => false)) of type object<GuzzleHttp\Client> is incompatible with the declared type object<Guzzle\Http\Client> of property $_client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
            [
47
                'allow_redirects' => false, //stop guzzle from following redirects
48
                'http_errors' => false, //only for 400/500 error codes, actual exceptions can still happen
49
            ]
50
        );
51
    }
52
53
    /**
54
     * @see Adapter::start()
55
     */
56
    public function start(Request $request)
57
    {
58
        $handle = uniqid();
59
        $this->_promises[$handle] = $this->_client->requestAsync(
0 ignored issues
show
The method requestAsync() does not seem to exist on object<Guzzle\Http\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            $request->getMethod(),
61
            $request->getUrl(),
62
            [
63
                'headers' => $request->getHeaders(),
64
                'body' => $request->getBody(),
65
            ]
66
        );
67
68
        return $handle;
69
    }
70
71
    /**
72
     * @see Adapter::end()
73
     *
74
     * @throws \InvalidArgumentException
75
     */
76
    public function end($endHandle)
77
    {
78
        $results = $this->fulfillPromises($this->_promises, $this->_exceptions);
79
        foreach ($results as $handle => $response) {
80
            try {
81
                $body = []; //default to empty body
82
                $contents = (string)$response->getBody();
83
                if (trim($contents) !== '') {
84
                    $body = json_decode($contents, true);
85
                    Util::ensure(
86
                        JSON_ERROR_NONE,
87
                        json_last_error(),
88
                        '\UnexpectedValueException',
89
                        [json_last_error_msg()]
90
                    );
91
                }
92
93
                $this->_responses[$handle] = new Response($response->getStatusCode(), $response->getHeaders(), $body);
94
            } catch (\Exception $e) {
95
                $this->_exceptions[$handle] = $e;
96
            }
97
        }
98
99
        $this->_promises = [];
100
101
        if (array_key_exists($endHandle, $this->_exceptions)) {
102
            $exception = $this->_exceptions[$endHandle];
103
            unset($this->_exceptions[$endHandle]);
104
            throw $exception;
105
        }
106
107
        if (array_key_exists($endHandle, $this->_responses)) {
108
            $response = $this->_responses[$endHandle];
109
            unset($this->_responses[$endHandle]);
110
            return $response;
111
        }
112
113
        throw new \InvalidArgumentException('$endHandle not found');
114
    }
115
116
    /**
117
     * Helper method to execute all guzzle promises.
118
     *
119
     * @param array $promises
120
     * @param array $exceptions
121
     *
122
     * @return array Array of fulfilled PSR7 responses.
123
     */
124
    private function fulfillPromises(array $promises, array &$exceptions)
125
    {
126
        if (empty($promises)) {
127
            return [];
128
        }
129
130
        $results = [];
131
        Promise\each(
132
            $this->_promises,
133
            function (ResponseInterface $response, $index) use (&$results) {
134
                $results[$index] = $response;
135
            },
136
            function (RequestException $e, $index) use (&$exceptions) {
137
                $exceptions[$index] = $e;
138
            }
139
        )->wait();
140
141
        return $results;
142
    }
143
}
144