Issues (3)

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/RestClient/CurlRestClient.php (3 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 RestClient;
4
5
/**
6
 * Class CurlRestClient
7
 * @package RestClient
8
 */
9
class CurlRestClient extends RestClient
10
{
11
    /**
12
     * @var $url null
13
     */
14
    private $url;
15
    /**
16
     * @var $header array
17
     */
18
    private $header;
19
    /**
20
     * @var $auth array
21
     */
22
    private $auth;
23
24
    /**
25
     * @var $options array
26
     */
27
    private $options = array();
28
29
    private $curl;
30
31
    /**
32
     * @param null $url
33
     * @param array $header
34
     * @param array $auth
35
     * @param array $options
36
     */
37
    public function __construct($url = null, $header = array(), $auth = array(), $options = array())
38
    {
39
        $this->url = $url;
40
        $this->header = $header;
41
        $this->auth = $auth;
42
        $this->options = $options;
43
    }
44
45
    /**
46
     * function setHeader
47
     * @param array $header
48
     */
49
    public function setHeader($header)
50
    {
51
        $this->header = $header;
52
    }
53
54
    /**
55
     * function setAuth
56
     * @param array $auth
57
     */
58
    public function setAuth($auth)
59
    {
60
        $this->auth = $auth;
61
    }
62
63
    /**
64
     * function setOptions
65
     * @param array $options
66
     */
67
    public function setOptions(array $options)
68
    {
69
        $this->options = $options;
70
    }
71
72
    /**
73
     * @param string $url
74
     * @param string $method
75
     * @param array $header
76
     * @param array $data
77
     * @param array $auth
78
     * @param bool $forceInit
79
     * @return mixed
80
     * @throws \Exception
81
     */
82
    public function executeQuery($url, $method = 'GET', $header = array(), $data = array(), $auth = array(), $forceInit = false)
83
    {
84
85
        if (true === $forceInit) {
86
            $this->close(); // close previous channel
87
        }
88
89
        if (null === $this->curl) {
90
            $this->curl = curl_init();
91
        }
92
93
        if ($method == 'GET')
94
            $url = $url . '?' . http_build_query($data);
95
96
        curl_setopt($this->curl, CURLOPT_URL, $url);
97
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header);
98
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
99
100
        if (!empty($auth)) {
101
            curl_setopt($this->curl, CURLOPT_HTTPAUTH, $auth['CURLOPT_HTTPAUTH']);
102
            curl_setopt($this->curl, CURLOPT_USERPWD, $auth['username'] . ':' . $auth['password']);
103
        }
104
105
        if (is_array($this->options)) {
106
            foreach ($this->options as $option => $value) {
107
                curl_setopt($this->curl, $option, $value);
108
            }
109
        }
110
111
        if ($method == 'POST') {
112
            curl_setopt($this->curl, CURLOPT_POST, true);
113 View Code Duplication
            if (!empty($data)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($data));
115
            } else {
116
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, array());
117
            }
118
        } elseif ($method == 'PUT') {
119
            curl_setopt($this->curl, CURLOPT_PUT, true);
120 View Code Duplication
            if (!empty($data)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($data));
122
            } else {
123
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, array());
124
            }
125
        } elseif ($method == 'DELETE') {
126
            curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, "DELETE");
127 View Code Duplication
            if (!empty($data)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($data));
129
            } else {
130
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, array());
131
            }
132
        }
133
134
        $content = curl_exec($this->curl);
135
136
        if (FALSE === $content)
137
            throw new \Exception(curl_error($this->curl), curl_errno($this->curl));
138
139
        return $content;
140
    }
141
142
    /**
143
     * function call
144
     * @param string $method
145
     * @param string $segment
146
     * @param array $data
147
     * @return array
148
     */
149
    private function call($method, $segment, $data = array())
150
    {
151
        return $this->executeQuery($this->url . '/' . $segment, $method, $this->header, $data, $this->auth);
152
    }
153
154
    /**
155
     * function get
156
     * @param string $segment
157
     * @param array $data
158
     * @return array
159
     */
160
    public function get($segment, $data = array())
161
    {
162
        return $this->call('GET', $segment, $data);
163
    }
164
165
    /**
166
     * function post
167
     * @param string $segment
168
     * @param array $data
169
     * @return array
170
     */
171
    public function post($segment, $data)
172
    {
173
        return $this->call('POST', $segment, $data);
174
    }
175
176
    /**
177
     * function put
178
     * @param string $segment
179
     * @param array $data
180
     * @return array
181
     */
182
    public function put($segment, $data)
183
    {
184
        return $this->call('PUT', $segment, $data);
185
    }
186
187
    /**
188
     * function delete
189
     * @param string $segment
190
     * @param array $data
191
     * @return array
192
     */
193
    public function delete($segment, $data)
194
    {
195
        return $this->call('DELETE', $segment, $data);
196
    }
197
198
    /**
199
     * function getName
200
     * @return string
201
     */
202
    public function getName()
203
    {
204
        return 'curl';
205
    }
206
207
    public function close()
208
    {
209
        if (null !== $this->curl) {
210
            curl_close($this->curl);
211
        }
212
213
        $this->curl = null;
214
    }
215
216
217
}
218