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 (1)

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/AuthenticationMiddleware.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
namespace CMPayments\GuzzlePSPAuthenticationMiddleware;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Class ConnectionMiddleware
9
 *
10
 * @package CMPayments\GuzzlePSPAuthenticationMiddleware
11
 */
12
class AuthenticationMiddleware
13
{
14
    /**
15
     * @var string
16
     */
17
    private $key;
18
19
    /**
20
     * @var string
21
     */
22
    private $secret;
23
24
    /**
25
     * @var NonceGeneratorInterface
26
     */
27
    private $nonceGenerator;
28
29
    /**
30
     * @var TimestampGeneratorInterface
31
     */
32
    private $timestampGenerator;
33
34
    /**
35
     * AuthenticationMiddleware constructor.
36
     *
37
     * @param string $key    OAuth-Consumer-Key
38
     * @param string $secret OAuth-Consumer-Secret
39
     */
40 2
    public function __construct($key, $secret)
41
    {
42 2
        $this->key = $key;
43 2
        $this->secret = $secret;
44
45 2
        $this->nonceGenerator = new RandomNonceGenerator();
46 2
        $this->timestampGenerator = new RandomTimestampGenerator();
47 2
    }
48
49
    /**
50
     * Overwrite the nonceGenerator-class. Used for the unit-test
51
     *
52
     * @param NonceGeneratorInterface $nonceGenerator
53
     */
54 2
    public function setNonceGenerator($nonceGenerator)
55
    {
56 2
        $this->nonceGenerator = $nonceGenerator;
57 2
    }
58
59
    /**
60
     * Overwrite the timestampGenerator-class. Used for the unit-test
61
     *
62
     * @param TimestampGeneratorInterface $timestampGenerator
63
     */
64 2
    public function setTimestampGenerator($timestampGenerator)
65
    {
66 2
        $this->timestampGenerator = $timestampGenerator;
67 2
    }
68
69
70
    /**
71
     * This function is called by Guzzle in order to initiate the middleware.
72
     *
73
     * @param callable $handler Representation of an outgoing, client-side request.
74
     *
75
     * @return \Closure
76
     */
77
    public function __invoke($handler)
78
    {
79 2
        return function ($request, array $options) use ($handler) {
80 2
            $request = $this->onBefore($request);
81
82 2
            return $handler($request, $options);
83 2
        };
84
    }
85
86
    /**
87
     * Before executing the request, add the extra headers
88
     *
89
     * @param RequestInterface $request
90
     *
91
     * @return RequestInterface
92
     */
93 2
    private function onBefore(RequestInterface $request)
94
    {
95 2
        $headers = $this->createHeaders($request);
96 2
        foreach ($headers as $headerKey => $headerValue) {
97 2
            $request = $request->withHeader($headerKey, $headerValue);
98 2
        }
99
100 2
        return $request;
101
    }
102
103
    /**
104
     * Calculate/determine the required headers for the request.
105
     *
106
     * @param RequestInterface $request
107
     *
108
     * @return string[] The headers for the request
0 ignored issues
show
Should the return type not be array<string,string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
109
     */
110 2
    private function createHeaders(RequestInterface $request)
111
    {
112 2
        $nonce = $this->nonceGenerator->generate();
113 2
        $timestamp = $this->timestampGenerator->generate();
114
115
        /** @var array $data */
116 2
        $data = $this->createDataElement($request, $nonce, $timestamp);
117
118 2
        $payload = $request->getMethod() .
119 2
            '&' . rawurlencode((string)$request->getUri()) .
120 2
            '&' . implode(rawurlencode('&'), $data);
121
122 2
        $signkey = rawurlencode($this->key) . '&' . rawurlencode($this->secret);
123 2
        $hash = rawurlencode(base64_encode(hash_hmac('sha256', $payload, $signkey)));
124
125
        /** @var array $oauth_header */
126 2
        $oauth_header = $this->createOAuthHeaders($nonce, $timestamp, $hash);
127
128 2
        $header = [];
129 2
        $header['Content-type'] = 'application/json';
130 2
        $header['Authorization'] = 'OAuth ' . implode(', ', $oauth_header);
131
132 2
        return $header;
133
    }
134
135
    /**
136
     * Create the data array for the payload
137
     *
138
     * @param RequestInterface $request
139
     * @param string           $nonce The none which is generated
140
     * @param int              $timestamp The timestamp which is generated
141
     *
142
     * @return string[] The data-array
143
     */
144 2
    private function createDataElement(RequestInterface $request, $nonce, $timestamp)
145
    {
146 2
        $data = [];
147 2
        if ($request->getMethod() === 'POST') {
148 1
            $data[] = rawurlencode($request->getBody()->getContents());
149 1
        }
150 2
        $data[] = rawurlencode('oauth_consumer_key=' . $this->key);
151 2
        $data[] = rawurlencode('oauth_nonce=' . $nonce);
152 2
        $data[] = rawurlencode('oauth_signature_method=HMAC-SHA256');
153 2
        $data[] = rawurlencode('oauth_timestamp=' . $timestamp);
154 2
        $data[] = rawurlencode('oauth_version=1.0');
155
156 2
        return $data;
157
    }
158
159
    /**
160
     * Create the oAuth headers
161
     *
162
     * @param string $nonce The generated nonce
163
     * @param int    $timestamp The generated timestamp
164
     * @param string $hash The created hash
165
     *
166
     * @return string[] The headers for the request
167
     */
168 2
    private function createOAuthHeaders($nonce, $timestamp, $hash)
169
    {
170 2
        $oauth_header = [];
171 2
        $oauth_header[] = 'oauth_consumer_key="' . $this->key . '"';
172 2
        $oauth_header[] = 'oauth_nonce="' . $nonce . '"';
173 2
        $oauth_header[] = 'oauth_signature="' . $hash . '"';
174 2
        $oauth_header[] = 'oauth_signature_method="HMAC-SHA256"';
175 2
        $oauth_header[] = 'oauth_timestamp="' . $timestamp . '"';
176 2
        $oauth_header[] = 'oauth_version="1.0"';
177 2
        return $oauth_header;
178
    }
179
}
180