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

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/Client/ApiClient.php (3 issues)

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
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\LastFm\Client;
11
12
use Core23\LastFm\Connection\ConnectionInterface;
13
use Core23\LastFm\Exception\ApiException;
14
use Core23\LastFm\Exception\NotFoundException;
15
use Core23\LastFm\Session\SessionInterface;
16
17
final class ApiClient implements ApiClientInterface
18
{
19
    /**
20
     * @var ConnectionInterface
21
     */
22
    private $connection;
23
24
    /**
25
     * @var string
26
     */
27
    private $apiKey;
28
29
    /**
30
     * @var string
31
     */
32
    private $sharedSecret;
33
34
    public function __construct(ConnectionInterface $connection, string $apiKey, string $sharedSecret)
35
    {
36
        $this->connection   = $connection;
37
        $this->apiKey       = $apiKey;
38
        $this->sharedSecret = $sharedSecret;
39
    }
40
41
    public function getApiKey(): string
42
    {
43
        return $this->apiKey;
44
    }
45
46
    public function getSharedSecret(): string
47
    {
48
        return $this->sharedSecret;
49
    }
50
51
    public function signedCall(string $method, array $params = [], SessionInterface $session = null, $requestMethod = 'GET'): array
52
    {
53
        // Call parameter
54
        $callParams = [
55
            'method'  => $method,
56
            'api_key' => $this->apiKey,
57
        ];
58
59
        // Add session key
60
        if (null !== $session) {
61
            $callParams['sk'] = $session->getKey();
62
        }
63
64
        $params = array_merge($callParams, $params);
65
        $params = $this->filterNull($params);
66
        $params = $this->encodeUTF8($params);
67
68
        // Sign parameter
69
        $params['api_sig'] = $this->signParams($params);
0 ignored issues
show
It seems like $params defined by $this->encodeUTF8($params) on line 66 can also be of type string; however, Core23\LastFm\Client\ApiClient::signParams() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
70
71
        return $this->call($method, $params);
0 ignored issues
show
It seems like $params defined by $this->encodeUTF8($params) on line 66 can also be of type string; however, Core23\LastFm\Client\ApiClient::call() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
72
    }
73
74
    public function unsignedCall(string $method, array $params = [], string $requestMethod = 'GET'): array
75
    {
76
        // Call parameter
77
        $callParameter = [
78
            'method'  => $method,
79
            'api_key' => $this->apiKey,
80
        ];
81
82
        $params = array_merge($callParameter, $params);
83
        $params = $this->filterNull($params);
84
        $params = $this->encodeUTF8($params);
85
86
        return $this->call($method, $params);
0 ignored issues
show
It seems like $params defined by $this->encodeUTF8($params) on line 84 can also be of type string; however, Core23\LastFm\Client\ApiClient::call() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
87
    }
88
89
    /**
90
     * Filter null values.
91
     */
92
    private function filterNull(array $object): array
93
    {
94
        return array_filter($object, static function ($val) {
95
            return null !== $val;
96
        });
97
    }
98
99
    /**
100
     * Converts any string or array of strings to UTF8.
101
     *
102
     * @param mixed|mixed[] $object a String or an array
103
     *
104
     * @return mixed|mixed[] UTF8-string or array
105
     */
106
    private function encodeUTF8($object)
107
    {
108
        if (\is_array($object)) {
109
            return array_map([$this, 'encodeUTF8'], $object);
110
        }
111
112
        return mb_convert_encoding((string) $object, 'UTF-8', 'auto');
113
    }
114
115
    private function signParams(array $params): string
116
    {
117
        ksort($params);
118
119
        $signature = '';
120
        foreach ($params as $name => $value) {
121
            $signature .= $name.$value;
122
        }
123
        $signature .= $this->sharedSecret;
124
125
        return md5($signature);
126
    }
127
128
    private function call(string $method, array $params): array
129
    {
130
        try {
131
            return $this->connection->call($method, $params);
132
        } catch (ApiException $e) {
133
            if (6 === (int) $e->getCode()) {
134
                throw new NotFoundException('No entity was found for your request.', $e->getCode(), $e);
135
            }
136
137
            throw $e;
138
        }
139
    }
140
}
141