1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Freyo\ApiGateway; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Freyo\ApiGateway\Kernel\Traits\WithFingerprint; |
7
|
|
|
|
8
|
|
|
class FingerprintMiddleware |
9
|
|
|
{ |
10
|
|
|
use WithFingerprint; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Handle an incoming request. |
14
|
|
|
* |
15
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
16
|
|
|
* @param \Closure $next |
17
|
|
|
* @return mixed |
18
|
|
|
*/ |
19
|
|
|
public function handle($request, Closure $next) |
20
|
|
|
{ |
21
|
|
|
$authorizations = $this->authorizations($request->header('authorization')); |
22
|
|
|
$headers = preg_split('/\s+/', $authorizations['headers'] ?? []); |
|
|
|
|
23
|
|
|
if (!in_array('fingerprint', $headers)) { |
|
|
|
|
24
|
|
|
return response()->json([ |
|
|
|
|
25
|
|
|
'message' => 'HMAC signature missing fingerprint header', |
26
|
|
|
], 401); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$fingerprint = $this->fingerprint($request->method(), $request->url(), $request->all()); |
30
|
|
|
if ($fingerprint !== $request->header('fingerprint')) { |
31
|
|
|
return response()->json([ |
32
|
|
|
'message' => 'fingerprint does not match', |
33
|
|
|
], 401); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $next($request); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $authorization |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
protected function authorizations($authorization) |
45
|
|
|
{ |
46
|
|
|
$authorization = preg_replace('/^hmac/i', '', $authorization); |
47
|
|
|
$params = array_map('trim', explode(',', $authorization)); |
48
|
|
|
|
49
|
|
|
$params = array_map(function ($item) { |
50
|
|
|
parse_str($item, $parsed); |
51
|
|
|
return array_map(function ($value) { |
52
|
|
|
return trim($value, '"\''); |
53
|
|
|
}, $parsed); |
54
|
|
|
}, $params); |
55
|
|
|
|
56
|
|
|
$result = []; |
57
|
|
|
foreach ($params as $param) { |
58
|
|
|
$result = array_merge($result, $param); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $result; |
62
|
|
|
} |
63
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths