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

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/Transport/Client.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
declare(strict_types=1);
3
4
namespace WyriHaximus\ApiClient\Transport;
5
6
use GuzzleHttp\Client as GuzzleClient;
7
use GuzzleHttp\Psr7\Request;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use React\Cache\CacheInterface;
11
use React\EventLoop\LoopInterface;
12
use React\Promise\Deferred;
13
use React\Promise\PromiseInterface;
14
use function React\Promise\reject;
15
use function React\Promise\resolve;
16
use function WyriHaximus\React\futureFunctionPromise;
17
18
class Client
19
{
20
    const DEFAULT_OPTIONS = [
21
        'schema' => 'https',
22
        'path' => '/',
23
        'user_agent' => 'WyriHaximus/php-api-client',
24
        'headers' => [],
25
    ];
26
27
    /**
28
     * @var GuzzleClient
29
     */
30
    protected $handler;
31
32
    /**
33
     * @var LoopInterface
34
     */
35
    protected $loop;
36
37
    /**
38
     * @var array
39
     */
40
    protected $options = [];
41
42
    /**
43
     * @var Hydrator
44
     */
45
    protected $hydrator;
46
47
    /**
48
     * @var CacheInterface
49
     */
50
    protected $cache;
51
52
    /**
53
     * @param LoopInterface $loop
54
     * @param GuzzleClient $handler
55
     * @param array $options
56
     */
57 12
    public function __construct(LoopInterface $loop, GuzzleClient $handler, array $options = [])
58
    {
59 12
        $this->loop = $loop;
60 12
        $this->handler = $handler;
61 12
        $this->options = $options + self::DEFAULT_OPTIONS;
62 12
        if (isset($this->options['cache']) && $this->options['cache'] instanceof CacheInterface) {
63 3
            $this->cache = $this->options['cache'];
64
        }
65 12
        $this->hydrator = new Hydrator($this, $options);
66 12
    }
67
68
    /**
69
     * @param string $path
70
     * @param bool $refresh
71
     * @return PromiseInterface
72
     */
73 5
    public function request(string $path, bool $refresh = false): PromiseInterface
74
    {
75
        return $this->requestRaw($path, $refresh)->then(function ($json) {
76 3
            return $this->jsonDecode($json);
77 5
        });
78
    }
79
80
    /**
81
     * @param string $path
82
     * @param bool $refresh
83
     * @return PromiseInterface
84
     */
85 5
    public function requestRaw(string $path, bool $refresh = false): PromiseInterface
86
    {
87 5
        if ($refresh) {
88 2
            return $this->sendRequest($path);
89
        }
90
91
        return $this->checkCache($path)->otherwise(function () use ($path) {
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface React\Promise\PromiseInterface as the method otherwise() does only exist in the following implementations of said interface: React\Promise\FulfilledPromise, React\Promise\LazyPromise, React\Promise\Promise, React\Promise\RejectedPromise.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
92 2
            return $this->sendRequest($path);
93 3
        });
94
    }
95
96
    /**
97
     * @param string $path
98
     * @return PromiseInterface
99
     */
100 3
    protected function checkCache(string $path): PromiseInterface
101
    {
102 3
        if ($this->cache instanceof CacheInterface) {
103 2
            return $this->cache->get($path);
104
        }
105
106 1
        return reject();
107
    }
108
109
    /**
110
     * @param string $path
111
     * @param string $method
112
     * @param bool $raw
113
     * @return PromiseInterface
114
     */
115 4
    protected function sendRequest(string $path, string $method = 'GET', bool $raw = false): PromiseInterface
116
    {
117 4
        return $this->requestPsr7(
118 4
            $this->createRequest($method, $path)
119
        )->then(function ($response) use ($path, $raw) {
120 2
            $json = $response->getBody()->getContents();
121
122 2
            if ($this->cache instanceof CacheInterface) {
123 2
                $this->cache->set($path, $json);
124
            }
125
126 2
            return resolve($json);
127 4
        });
128
    }
129
130
    /**
131
     * @param RequestInterface $request
132
     * @return PromiseInterface
133
     */
134 4
    public function requestPsr7(RequestInterface $request): PromiseInterface
135
    {
136 4
        $deferred = new Deferred();
137
138 4
        $this->handler->sendAsync(
139
            $request
140
        )->then(function (ResponseInterface $response) use ($deferred) {
141 2
            $deferred->resolve($response);
142
        }, function ($error) use ($deferred) {
143
            $deferred->reject($error);
144 4
        });
145
146 4
        return $deferred->promise();
147
    }
148
149
    /**
150
     * @param string $method
151
     * @param string $path
152
     * @return RequestInterface
153
     */
154 4
    protected function createRequest(string $method, string $path): RequestInterface
155
    {
156 4
        $url = $this->getBaseURL() . $path;
157 4
        $headers = $this->getHeaders();
158 4
        return new Request($method, $url, $headers);
159
    }
160
161
    /**
162
     * @return array
163
     */
164 4
    public function getHeaders(): array
165
    {
166
        $headers = [
167 4
            'User-Agent' => $this->options['user_agent'],
168
        ];
169 4
        $headers += $this->options['headers'];
170 4
        return $headers;
171
    }
172
173
    /**
174
     * @param string $json
175
     * @return PromiseInterface
176
     */
177
    public function jsonDecode(string $json): PromiseInterface
178
    {
179 3
        return futureFunctionPromise($this->loop, $json, function ($json) {
180 3
            return json_decode($json, true);
181 3
        });
182
    }
183
184
    /**
185
     * @return Hydrator
186
     */
187 1
    public function getHydrator(): Hydrator
188
    {
189 1
        return $this->hydrator;
190
    }
191
192
    /**
193
     * @return LoopInterface
194
     */
195 3
    public function getLoop(): LoopInterface
196
    {
197 3
        return $this->loop;
198
    }
199
200
    /**
201
     * @return string
202
     */
203 7
    public function getBaseURL(): string
204
    {
205 7
        return $this->options['schema'] . '://' . $this->options['host'] . $this->options['path'];
206
    }
207
}
208