|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_Serialize extends Kint_Parser_Plugin |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* Disables automatic unserialization on arrays and objects. |
|
7
|
|
|
* |
|
8
|
|
|
* As the PHP manual notes: |
|
9
|
|
|
* |
|
10
|
|
|
* > Unserialization can result in code being loaded and executed due to |
|
11
|
|
|
* > object instantiation and autoloading, and a malicious user may be able |
|
12
|
|
|
* > to exploit this. |
|
13
|
|
|
* |
|
14
|
|
|
* The natural way to stop that from happening is to just refuse to unserialize |
|
15
|
|
|
* stuff by default. Which is what we're doing for anything that's not scalar. |
|
16
|
|
|
* |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
public static $safe_mode = true; |
|
|
|
|
|
|
20
|
|
|
public static $options = array(true); |
|
21
|
|
|
|
|
22
|
|
|
public function getTypes() |
|
23
|
|
|
{ |
|
24
|
|
|
return array('string'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getTriggers() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
return Kint_Parser::TRIGGER_SUCCESS; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$trimmed = rtrim($var); |
|
35
|
|
|
|
|
36
|
|
|
if ($trimmed !== 'N;' && !preg_match('/^(?:[COabis]:\d+[:;]|d:\d+(?:\.\d+);)/', $trimmed)) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if (!self::$safe_mode || !in_array($trimmed[0], array('C', 'O', 'a'))) { |
|
41
|
|
|
$blacklist = false; |
|
42
|
|
|
|
|
43
|
|
|
// Second parameter only supported on PHP 7 |
|
44
|
|
|
if (KINT_PHP70) { |
|
45
|
|
|
// Suppress warnings on unserializeable variable |
|
46
|
|
|
$data = @unserialize($trimmed, self::$options); |
|
47
|
|
|
} else { |
|
48
|
|
|
$data = @unserialize($trimmed); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ($data === false && substr($trimmed, 0, 4) !== 'b:0;') { |
|
52
|
|
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
} else { |
|
55
|
|
|
$blacklist = true; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$base_obj = new Kint_Object(); |
|
|
|
|
|
|
59
|
|
|
$base_obj->depth = $o->depth + 1; |
|
|
|
|
|
|
60
|
|
|
$base_obj->name = 'unserialize('.$o->name.')'; |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
if ($o->access_path) { |
|
|
|
|
|
|
63
|
|
|
$base_obj->access_path = 'unserialize('.$o->access_path; |
|
|
|
|
|
|
64
|
|
|
if (!KINT_PHP70 || self::$options === array(true)) { |
|
65
|
|
|
$base_obj->access_path .= ')'; |
|
|
|
|
|
|
66
|
|
|
} elseif (self::$options === array(false)) { |
|
67
|
|
|
$base_obj->access_path .= ', false)'; |
|
|
|
|
|
|
68
|
|
|
} else { |
|
69
|
|
|
$base_obj->access_path .= ', Kint_Parser_Serialize::$options)'; |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$r = new Kint_Object_Representation('Serialized'); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
if ($blacklist) { |
|
76
|
|
|
$base_obj->hints[] = 'blacklist'; |
|
|
|
|
|
|
77
|
|
|
$r->contents = $base_obj; |
|
|
|
|
|
|
78
|
|
|
} else { |
|
79
|
|
|
$r->contents = $this->parser->parse($data, $base_obj); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$o->addRepresentation($r, 0); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.