Issues (124)

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/Integracao/ControlPay/AbstractAPI.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
namespace Integracao\ControlPay;
3
4
use GuzzleHttp;
5
use Integracao\ControlPay\Constants\ControlPayParameterConst;
6
use Integracao\ControlPay\Impl\BasicAuthentication;
7
use Integracao\ControlPay\Impl\KeyQueryStringAuthentication;
8
9
/**
10
 * Class AbstractAPI
11
 * @package Integracao\NTKPedido
12
 */
13
abstract class AbstractAPI
14
{
15
    /**
16
     * @var Client
17
     */
18
    protected $_client;
19
20
    /**
21
     * @var GuzzleHttp\Client
22
     */
23
    protected $_httpClient;
24
25
    /**
26
     * @var string
27
     */
28
    protected $url;
29
30
    /**
31
     * @var string
32
     */
33
    protected $endpoint;
34
35
    /**
36
     * @var GuzzleHttp\Query
37
     */
38
    protected $query;
39
40
    /**
41
     * @var GuzzleHttp\Message\ResponseInterface
42
     */
43
    protected $response;
44
45
    /**
46
     * @var array
47
     */
48
    protected $headers = [
49
        'Content-Type' => 'application/json; charset=utf-8',
50
        'Cache-Control' => 'no-cache',
51
    ];
52
53
    /**
54
     * AbstractAPI constructor.
55
     * @param $endpoint
56
     * @param Client|null $client
57
     */
58
    protected function __construct($endpoint, Client $client = null)
59
    {
60
        $this->endpoint = $endpoint;
61
        $this->_client = $client;
62
63
        if(is_null($this->_client))
64
            $this->_client = new Client();
65
66
        $this->query = new GuzzleHttp\Query();
67
        $this->query->setEncodingType(false);
68
69
        switch ($this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE))
70
        {
71
            case KeyQueryStringAuthentication::class:
72
                $this->query->set('key', $this->_client->getAuthentication());
73
                break;
74
            case BasicAuthentication::class:
75
                $this->headers['Authorization'] = $this->_client->getAuthentication();
76
                break;
77
            default:
78
                $this->query->set('key', $this->_client->getAuthentication());
79
                break;
80
        }
81
82
        $this->_httpClient = new GuzzleHttp\Client([
83
            'base_url' => sprintf("%s/%s/",
84
                $client->getParameter(ControlPayParameterConst::CONTROLPAY_HOST),
0 ignored issues
show
It seems like $client is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
85
                $this->endpoint
86
            ),
87
            'timeout' => $client->getParameter(ControlPayParameterConst::CONTROLPAY_TIMEOUT),
88
            'verify' => false,
89
            'defaults' => [
90
                'headers' => $this->headers,
91
                'query' => $this->query
92
            ]
93
        ]);
94
    }
95
96
    /**
97
     * Adiciona parâmetros mantendo os já inicializados como padrão
98
     *
99
     * @param array $params
100
     * @return string
101
     */
102
    protected function addQueryAdditionalParameters(array $params)
103
    {
104
        $this->query = new GuzzleHttp\Query();
105
106
        if(isset($this->_httpClient->getDefaultOption()['query']))
107
            $this->query = $this->_httpClient->getDefaultOption()['query'];
108
109
        foreach ($params as $key => $value)
110
            $this->query->set($key, $value);
111
112
        return $this->query;
113
    }
114
115
    /**
116
     * @return GuzzleHttp\Message\ResponseInterface
117
     */
118
    public function getResponse()
119
    {
120
        return $this->response;
121
    }
122
123
    /**
124
     * @return array
125
     */
126
    public function getQueryParameters()
127
    {
128
        return isset($this->_httpClient->getDefaultOption()['query']) ?
129
            $this->_httpClient->getDefaultOption()['query'] : [];
130
    }
131
132
    /**
133
     * @return array
134
     */
135
    public function getHeaders()
136
    {
137
        return isset($this->_httpClient->getDefaultOption()['headers']) ?
138
            $this->_httpClient->getDefaultOption()['headers'] : [];
139
    }
140
141
    /**
142
     * @param GuzzleHttp\Exception\RequestException $ex
143
     * @param string $message
144
     * @throws \Exception
145
     */
146
    protected function requestException(GuzzleHttp\Exception\RequestException $ex, $message = "Falha de requisição")
147
    {
148
        if ($ex->hasResponse())
149
        {
150
            throw new \Exception(sprintf("%s code => [%s] body => [%s]",
151
                $message,
152
                $ex->getResponse()->getStatusCode(),
153
                $ex->getResponse()->getBody())
154
            );
155
        }
156
157
        throw new \Exception($message, $ex->getCode(), $ex);
158
    }
159
160
}