GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (19)

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/Resource/ResourceBase.php (1 issue)

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
/**
4
 * Resource base class.
5
 *
6
 * Abstract resource base class.
7
 */
8
9
namespace zaporylie\Vipps\Resource;
10
11
use Doctrine\Common\Annotations\AnnotationRegistry;
12
use Http\Client\Exception\HttpException;
13
use Http\Client\HttpAsyncClient;
14
use Http\Client\HttpClient;
15
use JMS\Serializer\SerializerBuilder;
16
use Psr\Http\Message\RequestInterface;
17
use zaporylie\Vipps\Exceptions\VippsException;
18
use zaporylie\Vipps\VippsInterface;
19
20
/**
21
 * Class ResourceBase
22
 * @package Vipps\Resources
23
 */
24
abstract class ResourceBase implements ResourceInterface, SerializableInterface
25
{
26
27
    /**
28
     * @var VippsInterface
29
     */
30
    protected $app;
31
32
    /**
33
     * @var array
34
     */
35
    protected $headers = [];
36
37
    /**
38
     * @var string
39
     */
40
    protected $body = '';
41
42
    /**
43
     * @var string
44
     */
45
    protected $id;
46
47
    /**
48
     * @var string
49
     */
50
    protected $path;
51
52
    /**
53
     * @var \zaporylie\Vipps\Resource\HttpMethod
54
     */
55
    protected $method;
56
57
    /**
58
     * @var \JMS\Serializer\Serializer
59
     */
60
    protected $serializer;
61
62
    /**
63
     * AbstractResource constructor.
64
     *
65
     * @param \zaporylie\Vipps\VippsInterface $vipps
66
     * @param string $subscription_key
67
     */
68
    public function __construct(VippsInterface $vipps, $subscription_key)
69
    {
70
        $this->app = $vipps;
71
72
        $this->headers['Ocp-Apim-Subscription-Key'] = $subscription_key;
73
74
        // Initiate serializer.
75
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...istry::registerLoader() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
        $this->serializer = SerializerBuilder::create()
77
            ->build();
78
    }
79
80
    /**
81
     * Gets serializer value.
82
     *
83
     * @return \JMS\Serializer\Serializer
84
     */
85
    public function getSerializer()
86
    {
87
        return $this->serializer;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getHeaders()
94
    {
95
        return $this->headers;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getMethod()
102
    {
103
        if (!isset($this->method)) {
104
            throw new \LogicException('Missing HTTP method');
105
        }
106
        return $this->method;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     *
112
     * All occurrences of {id} pattern will be replaced with $this->id
113
     */
114
    public function getPath()
115
    {
116
        if (!isset($this->path)) {
117
            throw new \LogicException('Missing resource path');
118
        }
119
        // Get local var.
120
        $path = $this->path;
121
        // If ID is set replace {id} pattern with model's ID.
122
        if (isset($this->id)) {
123
            $path = str_replace('{id}', $this->id, $path);
124
        }
125
        return $path;
126
    }
127
128
    /**
129
     * Sets path variable.
130
     *
131
     * @param string $path
132
     *
133
     * @return $this
134
     */
135
    public function setPath($path)
136
    {
137
        $this->path = $path;
138
        return $this;
139
    }
140
141
    /**
142
     * @return string
143
     */
144
    public function getBody()
145
    {
146
        return $this->body;
147
    }
148
149
    /**
150
     * @param $path
151
     *
152
     * @return \Psr\Http\Message\UriInterface
153
     */
154
    public function getUri($path)
155
    {
156
        return $this->app->getClient()->getEndpoint()->getUri()->withPath($path);
157
    }
158
159
    /**
160
     * @return \Psr\Http\Message\ResponseInterface
161
     *
162
     * @throws \zaporylie\Vipps\Exceptions\VippsException
163
     */
164
    protected function makeCall()
165
    {
166
        try {
167
            $request = $this->getRequest();
168
            $response = $this->handleRequest($request);
169
        } catch (HttpException $e) {
170
            // Catch exceptions thrown by http client.
171
            // We must do that in order to normalize output.
172
            $response = $e->getResponse();
173
        } catch (\Exception $e) {
174
            // Something went really bad here.
175
            throw new VippsException($e->getMessage(), $e->getCode(), $e);
176
        }
177
        return $this->handleResponse($response);
178
    }
179
180
    /**
181
     * @param \Psr\Http\Message\RequestInterface $request
182
     *
183
     * @return \Psr\Http\Message\ResponseInterface
184
     */
185
    protected function handleRequest(RequestInterface $request)
186
    {
187
        // Get client.
188
        $client = $this->app->getClient()->getHttpClient();
189
190
        // Handle requests, sync precedence.
191
        if ($client instanceof HttpClient) {
192
            // Send sync request.
193
            $response = $client->sendRequest($request);
194
        } elseif ($client instanceof HttpAsyncClient) {
195
            // Send async request.
196
            $response = $client->sendAsyncRequest($request)->wait();
197
        } else {
198
            throw new \LogicException('Unknown HTTP Client type: '. implode(',', class_implements($client)));
199
        }
200
201
        return $response;
202
    }
203
204
    /**
205
     * @return \Psr\Http\Message\RequestInterface
206
     */
207
    protected function getRequest()
208
    {
209
        return $this->app->getClient()->getMessageFactory()->createRequest(
210
            $this->getMethod(),
211
            $this->getUri($this->getPath()),
212
            $this->getHeaders(),
213
            $this->getBody()
214
        );
215
    }
216
217
    /**
218
     * @param \Psr\Http\Message\ResponseInterface $response
219
     *
220
     * @return \Psr\Http\Message\ResponseInterface
221
     *
222
     * @throws \zaporylie\Vipps\Exceptions\VippsException
223
     */
224
    protected function handleResponse($response)
225
    {
226
        // Handle request errors.
227
        if ($response->getStatusCode() >= 400) {
228
            throw VippsException::createFromResponse($response, $this->getSerializer());
229
        }
230
231
        // Sometimes VIPPS returns 200 with error message :/ They promised
232
        // to fix it but as a temporary fix we are gonna check if body is
233
        // "invalid" and throw exception in such a case.
234
        $exception = VippsException::createFromResponse($response, $this->getSerializer(), false);
235
        if ($exception instanceof VippsException) {
236
            throw $exception;
237
        }
238
239
        return $response;
240
    }
241
}
242