Issues (14)

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/Message/AbstractRequest.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
/**
3
 * Abstract Request
4
 */
5
6
namespace IBM\Watson\Common\Message;
7
8
use GuzzleHttp\ClientInterface;
9
use GuzzleHttp\Psr7\Response;
10
use IBM\Watson\Common\Helper;
11
use IBM\Watson\Common\Exception\RuntimeException;
12
use SebastianBergmann\Environment\Runtime;
13
use Symfony\Component\HttpFoundation\ParameterBag;
14
use Symfony\Component\HttpFoundation\Request;
15
16
/**
17
 * Abstract Request
18
 *
19
 * This abstract class implements RequestInterface and defines a basic
20
 * set of functions that all Watson Requests are intended to include.
21
 *
22
 * @see RequestInterface
23
 * @see AbstractResponse
24
 */
25
abstract class AbstractRequest implements RequestInterface
26
{
27
    /**
28
     * The request parameters
29
     *
30
     * @var \Symfony\Component\HttpFoundation\ParameterBag
31
     */
32
    protected $parameters;
33
34
    /**
35
     * The request client
36
     *
37
     * @var \GuzzleHttp\ClientInterface
38
     */
39
    protected $httpClient;
40
41
    /**
42
     * The HTTP request object
43
     *
44
     * @var \Symfony\Component\HttpFoundation\Request
45
     */
46
    protected $httpRequest;
47
48
    /**
49
     * An associated ResponseInterface
50
     *
51
     * @var ResponseInterface
52
     */
53
    protected $response;
54
55
    /**
56
     * Create a new Request
57
     *
58
     * @param ClientInterface   $httpClient A Guzzle client to make API class with
59
     * @param Request           $httpRequest A Symfony HTTP request object
60
     */
61 18
    public function __construct(ClientInterface $httpClient, Request $httpRequest)
0 ignored issues
show
You have injected the Request via parameter $httpRequest. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
62
    {
63 18
        $this->httpClient = $httpClient;
64 18
        $this->httpRequest = $httpRequest;
65 18
        $this->initialize();
66 18
    }
67
68
    /**
69
     * Initialize the object with parameters
70
     *
71
     * Any unknown parameters passed will be ignored
72
     *
73
     * @param array $parameters an associative array of parameters
74
     *
75
     * @return $this
76
     * @throws RuntimeException
77
     */
78 30
    public function initialize(array $parameters = [])
79
    {
80 30
        if (null !== $this->response) {
81 3
            throw new RuntimeException('Request cannot be modified after it has been sent!');
82
        }
83
84 30
        $this->parameters = new ParameterBag;
85
86 30
        Helper::initialize($this, $parameters);
87
88 30
        return $this;
89
    }
90
91
    /**
92
     * Send the request
93
     *
94
     * @return ResponseInterface
95
     */
96 12
    public function send()
97
    {
98 12
        $data = $this->getData();
99
100 12
        return $this->sendData($data);
101
    }
102
103
    /**
104
     * Get all parameters
105
     *
106
     * @return array
107
     */
108 6
    public function getParameters()
109
    {
110 6
        return $this->parameters->all();
111
    }
112
113
    /**
114
     * Get a single parameter
115
     *
116
     * @param string $key The parameter key
117
     *
118
     * @return mixed
119
     */
120 9
    public function getParameter($key)
121
    {
122 9
        return $this->parameters->get($key);
123
    }
124
125
    /**
126
     * Set a single parameter
127
     *
128
     * @param string $key   The parameter key
129
     * @param mixed $value  The value to set
130
     *
131
     * @return AbstractRequest $this Provides a fluent interface
132
     * @throws RuntimeException if a request parameter is modified after the request is sent
133
     */
134 15
    protected function setParameter($key, $value)
135
    {
136 15
        if (null !== $this->response) {
137 3
            throw new RuntimeException('Request cannot be modified after it has been sent!');
138
        }
139
140 12
        $this->parameters->set($key, $value);
141
142 12
        return $this;
143
    }
144
145
    /**
146
     * Sets the username of the request
147
     *
148
     * @param string $value
149
     *
150
     * @return AbstractRequest
151
     */
152 12
    public function setUsername($value)
153
    {
154 12
        return $this->setParameter('username', $value);
155
    }
156
157
    /**
158
     * Gets the username of the request
159
     *
160
     * @return string
161
     */
162 6
    public function getUsername()
163
    {
164 6
        return $this->getParameter('username');
165
    }
166
167
    /**
168
     * Sets the password of the request
169
     *
170
     * @param string $value
171
     *
172
     * @return AbstractRequest
173
     */
174 9
    public function setPassword($value)
175
    {
176 9
        return $this->setParameter('password', $value);
177
    }
178
179
    /**
180
     * Gets the password of the request
181
     *
182
     * @return mixed
183
     */
184 6
    public function getPassword()
185
    {
186 6
        return $this->getParameter('password');
187
    }
188
189
    /**
190
     * Get the associated Response
191
     *
192
     * @return ResponseInterface
193
     */
194 6
    public function getResponse()
195
    {
196 6
        if (null === $this->response) {
197 3
            throw  new RuntimeException('You must call send() before accessing the response!');
198
        }
199
200 3
        return $this->response;
201
    }
202
}
203