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

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/JWT.php (2 issues)

Labels

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 Gandung\JWT;
4
5
use Gandung\JWT\Manager\KeyManagerInterface;
6
use Gandung\JWT\Token\JoseBuilderInterface;
7
use Gandung\JWT\Token\PayloadBuilderInterface;
8
use Gandung\JWT\Proxy\HMAC;
9
use Gandung\JWT\Proxy\RSA;
10
use Gandung\JWT\Proxy\ECDSA;
11
use Gandung\JWT\Parser\Parser;
12
use Gandung\JWT\Parser\ParserInterface;
13
14
/**
15
 * @author Paulus Gandung Prakosa <[email protected]>
16
 */
17
class JWT
18
{
19
    /**
20
     * @var array
21
     */
22
    private $algo = [];
23
24
    /**
25
     * @var array
26
     */
27
    private $proxy;
28
29
    /**
30
     * @var ParserInterface
31
     */
32
    private $parser;
33
34
    public function __construct(ParserInterface $parser)
35
    {
36
        $this->proxy = [
37
            'hmac' => HMAC::create(),
38
            'rsa' => RSA::create(),
39
            'ecdsa' => ECDSA::create()
40
        ];
41
        $this->parser = $parser;
42
    }
43
44
    /**
45
     * For chainability purpose.
46
     */
47
    public static function create()
48
    {
49
        return new static(new Parser());
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function createToken(
56
        JoseBuilderInterface $jose,
57
        PayloadBuilderInterface $payload,
58
        KeyManagerInterface $key
59
    ) {
60
        $portion = [];
61
62
        $portion[] = $jose->getValue();
63
        $portion[] = $payload->getValue();
64
        $currentAlgo = $portion[0]['alg'];
65
66
        $this->determineSigningAlgorithm($currentAlgo);
67
        $this->validateKey($key, $currentAlgo);
68
69
        $portion = join('.', \array_map(function ($q) {
70
            return \Gandung\JWT\__jwt_base64UrlEncode(
71
                \json_encode(
72
                    $q,
73
                    JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
74
                )
75
            );
76
        }, $portion));
77
78
        $signature = $this->algo[$currentAlgo]->sign($portion, $key);
79
80
        return $portion . '.' . \Gandung\JWT\__jwt_base64UrlEncode($signature);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function verifyToken(
87
        $expected,
88
        JoseBuilderInterface $jose,
89
        PayloadBuilderInterface $payload,
90
        KeyManagerInterface $key
91
    ) {
92
        $portion = [];
93
        $portion[] = $jose->getValue();
94
        $portion[] = $payload->getValue();
95
96
        $this->parser->parse($expected);
97
98
        $signature = $this->parser->getSignature();
99
        $currentAlgo = $portion[0]['alg'];
100
101
        $this->determineSigningAlgorithm($currentAlgo);
102
103
        $portion = join('.', \array_map(function ($q) {
104
            return \Gandung\JWT\__jwt_base64UrlEncode(
105
                \json_encode(
106
                    $q,
107
                    JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
108
                )
109
            );
110
        }, $portion));
111
112
        return $this->algo[$currentAlgo]->verify(
113
            $signature,
114
            $portion,
115
            $key
116
        );
117
    }
118
119
    private function determineSigningAlgorithm($algorithm)
120
    {
121
        if (!isset($this->algo[$algorithm])) {
122
            if ($algorithm[0] === 'H') {
123
                $this->algo[$algorithm] = \call_user_func([$this->proxy['hmac'], 'get' . $algorithm]);
124
            } elseif ($algorithm[0] === 'R') {
125
                $this->algo[$algorithm] = \call_user_func([$this->proxy['rsa'], 'get' . $algorithm]);
126
            } elseif ($algorithm[0] === 'E') {
127
                $this->algo[$algorithm] = \call_user_func([$this->proxy['ecdsa'], 'get' . $algorithm]);
128
            }
129
        }
130
    }
131
132
    private function validateKey(KeyManagerInterface $key, $algorithm)
133
    {
134
        $header = [
135
            'R' => ['BEGIN PRIVATE KEY', 'BEGIN ENCRYPTED PRIVATE KEY'],
136
            'E' => 'BEGIN EC PRIVATE KEY'
137
        ];
138
139
        if ($algorithm[0] === 'H') {
140
            return;
141
        }
142
143
        $content = $key->getContent();
144
145
        if (is_array($header[$algorithm[0]])) {
146
            foreach ($header[$algorithm[0]] as $h) {
0 ignored issues
show
The expression $header[$algorithm[0]] of type array<integer,string,{"0...","1":"string"}>|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
147
                $isHeaderMatched = strpos($content, $h) === false
148
                    ? false
149
                    : true;
150
151
                if ($isHeaderMatched) {
152
                    break;
153
                }
154
            }
155
        } else {
156
            $isHeaderMatched = strpos($content, $header[$algorithm[0]]) === false
157
                ? false
158
                : true;
159
        }
160
161
        if ($algorithm[0] === 'R' || $algorithm[0] === 'E') {
162
            if (false === $isHeaderMatched) {
0 ignored issues
show
The variable $isHeaderMatched does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
163
                throw new \InvalidArgumentException(
164
                    "PEM certificate must provided in RSA or ECDSA signing mode."
165
                );
166
            }
167
        }
168
    }
169
}
170