Completed
Push — master ( 381557...d947b3 )
by Ashley
01:11
created

Stripe::headers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Clarkeash\Shield\Services;
4
5
use Clarkeash\Shield\Contracts\Service;
6
use Illuminate\Http\Request;
7
8
class Stripe implements Service
9
{
10
    public function verify(Request $request): bool
11
    {
12
        $processed = $this->process($request->header('Stripe-Signature'));
0 ignored issues
show
Bug introduced by
It seems like $request->header('Stripe-Signature') targeting Illuminate\Http\Concerns...actsWithInput::header() can also be of type array; however, Clarkeash\Shield\Services\Stripe::process() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
13
14
        $tolerance = config('shield.services.stripe.tolerance', 60 * 5);
15
16
        if(($tolerance > 0) && ((time() - $processed['t']) > $tolerance)) {
17
            return false;
18
        }
19
20
        $payload = $processed['t'] . '.' . $request->getContent();
21
        $generated = hash_hmac('sha256', $payload, config('shield.services.stripe.token'));
22
23
        return hash_equals($generated, $processed['v1']);
24
    }
25
26
    protected function process(string $header)
27
    {
28
        $sections = explode(',', $header);
29
30
        $data = [];
31
32
        foreach ($sections as $section) {
33
            $parts = explode('=', $section);
34
            $data[$parts[0]] = $parts[1];
35
        }
36
37
        return $data;
38
    }
39
40
    public function headers(): array
41
    {
42
        return ['Stripe-Signature'];
43
    }
44
}
45