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.
Completed
Push — develop ( 1f0e95...207e01 )
by
unknown
03:09
created

VerifyReCaptcha   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 5
dl 0
loc 51
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C handle() 0 41 8
1
<?php
2
3
namespace Pterodactyl\Http\Middleware;
4
5
use Closure;
6
use Alert;
7
use \Pterodactyl\Events\Auth\FailedCaptcha;
8
9
class VerifyReCaptcha
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @param  \Closure  $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        if (!config('recaptcha.enabled')) return next($request);
21
        
22
        $response_domain = null;
23
24
        if ($request->has('g-recaptcha-response')) {
25
            $response = $request->get('g-recaptcha-response');
26
27
            $client = new \GuzzleHttp\Client();
28
            $res = $client->post('https://www.google.com/recaptcha/api/siteverify', [
29
                'form_params' => [
30
                    'secret' => config('recaptcha.secret_key'),
31
                    'response' => $response,
32
                ],
33
            ]);
34
35
            if ($res->getStatusCode() === 200) {
36
                $result = json_decode($res->getBody());
37
38
                $response_domain = $result->hostname;
39
40
                // Compare the domain received by google with the app url
41
                $domain_verified = false;
42
                if (config('recaptcha.verify_domain')) {
43
                   $matches;
0 ignored issues
show
Bug introduced by
The variable $matches seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
44
                   preg_match('/^(?:https?:\/\/)?((?:www\.)?[^:\/\n]+)/', config('app.url'), $matches);
45
                   $domain = $matches[1];
46
                   $domain_verified = $response_domain === $domain;
47
                }
48
49
                if ($result->success && (!config('recaptcha.verify_domain') || $domain_verified)) {
50
                    return $next($request);
51
                }
52
            }
53
        }
54
        
55
        // Emit an event and return to the previous view with an error (only the captcha error will be shown!)
56
        event(new FailedCaptcha($request->ip(), $response_domain));
57
        return back()->withErrors(['g-recaptcha-response' => trans('strings.captcha_invalid')])->withInput();
58
    }
59
}
60