Total Complexity | 7 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | final class HttpHeaderSanitizer |
||
6 | { |
||
7 | /** |
||
8 | * @var array Default list of keys to sanitise |
||
9 | * |
||
10 | * @link https://github.com/elastic/apm/blob/master/docs/agents/agent-development.md#http-transactions |
||
11 | */ |
||
12 | private static $wildcards = [ |
||
13 | 'password', |
||
14 | 'passwd', |
||
15 | 'pwd', |
||
16 | 'secret', |
||
17 | '*key', |
||
18 | '*token*', |
||
19 | '*session*', |
||
20 | '*credit*', |
||
21 | '*card*', |
||
22 | 'authorization', |
||
23 | 'set-cookie', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @param array $headers |
||
28 | * |
||
29 | * @return array |
||
30 | */ |
||
31 | 25 | public static function sanitize(array $headers) |
|
32 | { |
||
33 | 25 | $result = []; |
|
34 | |||
35 | 25 | foreach ($headers as $key => $value) { |
|
36 | 23 | if (false === self::headerMath($key)) { |
|
37 | 1 | $result[$key] = $value; |
|
38 | 1 | } |
|
39 | 25 | } |
|
40 | |||
41 | 25 | return $result; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param string $header |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | 23 | private static function headerMath($header) |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $pattern |
||
64 | * @param string $subject |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | 23 | private static function wildcardMatch($pattern, $subject) |
|
81 |